ColumnMapT: MapValueView operator== and operator!= do not compile, and the comparison logic is wrong
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 45/100
Rechercherichtung
Start with clickhouse/columns/map.h, especially MapValueView::operator== around the reported lines 201–213. Reproduce the compile error with the provided C++ example, then check how ArrayValueView::operator== uses element comparisons. Resolve the comparison semantics for pair ordering and duplicate keys, and verify that equality and inequality compile and match the chosen behavior.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Symptom
A program that compares two values of a ColumnMapT column with == or != (col.At(0) == col.At(1)) does not compile. A comparison of two Array(Map(...)) values (ColumnArrayT<ColumnMapT<...>>::At(i) == At(j)) fails the same way, because ArrayValueView::operator== calls != on its elements. The failure occurs with clang 18 (libstdc++ 13 and libc++ 18) and with gcc 13. No test or code in the repository calls these operators, so the build of the library and its tests does not show the problem.
Reproduction
#include <clickhouse/columns/map.h>
#include <clickhouse/columns/numeric.h>
#include <clickhouse/columns/string.h>
#include <iostream>
#include <map>
using namespace clickhouse;
int main() {
ColumnMapT<ColumnUInt64, ColumnString> col(std::make_shared<ColumnUInt64>(), std::make_shared<ColumnString>());
std::map<uint64_t, std::string> m{{1, "a"}, {2, "b"}};
col.Append(m);
col.Append(m);
std::cout << (col.At(0) == col.At(1)) << std::endl; // expected: 1
}
Compiler output (clang 18, libstdc++):
error: no matching function for call to object of type '(lambda at clickhouse/columns/map.h:209:25)'
clickhouse/columns/map.h:209:25: note: candidate function template not viable: no known conversion from 'const std::tuple<unsigned long, std::basic_string_view<char>>' to 'size_t' (aka 'unsigned long') for 2nd argument
With libc++: static assertion failed ... The comparator has to be callable.
Expected vs actual
Expected: the program compiles and prints 1. The server gives 1 for the same values:
SELECT map(1,'a',2,'b') = map(1,'a',2,'b') → 1.
Actual: compile error.
The comparison logic is also wrong. Results with local patches of map.h (gtest, the values in Map literal form):
| Local patch | Comparison | Result | Server |
|---|---|---|---|
| comparator callable in both argument orders | {1:'a',2:'b'} == {1:'a',2:'b'} |
false |
1 |
| comparator and index size | {1:'a',1:'a'} == {1:'a',2:'b'} |
false |
0 |
| comparator and index size | {1:'a',2:'b'} == {1:'a',1:'a'} |
true |
0 |
Root cause
clickhouse/columns/map.h:208-209: the comparator ofstd::binary_searchtakes(const auto& l, size_t r), butbinary_searchalso calls it with the arguments in the other order (index element, searched pair), so the call does not compile.clickhouse/columns/map.h:201:std::vector<size_t> result{data.Size()};selects the initializer-list constructor, so the index has one element, and only the first pair ofthisis found.clickhouse/columns/map.h:207-213: the check "each pair ofotheris inthis" is not symmetric when a map has duplicate keys (a Map can have them).
The fix is in MapValueView::operator== only. A maintainer must decide the semantics: the server compares Map values in order (map(1,'a',2,'b') = map(2,'b',1,'a') → 0), but operator== sorts an index, so it ignores the order of the pairs.
Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Environment
- clickhouse-cpp
masterd64b472 (the same code is in v2.6.2 and since v2.4.0) - ClickHouse server 26.11.2.4 (expected values only)
- clang 18.1.3 and gcc 13.3.0, Ubuntu 24.04, C++17
Classification: impact: none · area: Data types & formats (Map)
Found by automated analysis (Polyglot AI) while working on a check of ClickHouse/clickhouse-js#996 against this client. Verified against a live server.
- Vorherrschende Sprache
- C
- Sterne
- 388
- Forks
- 220
- Ø Merge
- 1 T. 25 Min.
- Gemergte PRs (30 T.)
- 16
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus ClickHouse/clickhouse-cpp
-
bug data-types
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
ClickHouse/clickhouse-cpp#645 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug queries
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 79/100
ClickHouse/clickhouse-cpp#644 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug data-types native-format
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
ClickHouse/clickhouse-cpp#643 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug connectivity native-protocol
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
ClickHouse/clickhouse-cpp#638 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Core SQL test harness: ParseSetAssignments does not skip comments inside SETEvtl. vergeben @puretechteam hat das vor 12 Tagen übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
ClickHouse/clickhouse-cpp#626 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in ClickHouse/clickhouse-cpp
Ähnliche Issues
-
CF_CFDP_S_SendFileData computes the file checksum from the SB buffer after CFE_SB_TransmitBufferOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
needs triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
389ds/389-ds-base#8251 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100