Core SQL test harness: ParseSetAssignments does not skip comments inside SET

Offen Anfängerfreundlich
#626 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@puretechteam arbeitet bereits daran.

Seit 23.11.2026.

  • #627 von @puretechteam — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
85/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
cpp
Bereich
testing

Rechercherichtung

Beginne in tests/clickhouse-test-runner/runner.cpp bei ParseSetAssignments (Zeilen 278-316), insbesondere bei der Split-Schleife und add; verwende SkipWhitespaceAndComments aus tests/clickhouse-test-runner/sql_text.cpp wieder. Füge den Fall ParseSetAssignments.Comments zu tests/clickhouse-test-runner/ut/args_ut.cpp hinzu, baue dann mit tests/clickhouse-test-runner/scripts/build.sh und führe den Unit-Test des Runners mit --gtest_filter=ParseSetAssignments.Comments aus. Fertig bedeutet, dass die drei Einstellungen ohne Kommentartext in Namen oder Werten geparst werden und ein ' innerhalb eines Kommentars spätere Zuweisungen nicht mehr verbirgt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug
Description

The shim of the core SQL test harness (tests/clickhouse-test-runner) reads the SET statements of a test to follow the session state, as clickhouse-client does: after a successful SET, Runner::AfterSuccess removes every assigned setting name from settings_ so that the command-line value (--max_threads=7) stops being sent as an IMPORTANT query setting and the session value applies.

ParseSetAssignments (tests/clickhouse-test-runner/runner.cpp:278-316) skips comments only before the SET keyword (line 280, SkipWhitespaceAndComments(sql, 0) + 3). The body is then split on , / = with the comments still in place, and the split loop (lines 301-313) handles ', ", ` quoting and (/[ nesting but not --, # or /* */ comments. Consequences:

  1. A comment before a setting name becomes part of the name, so AfterSuccess (line 270) does not erase the command-line setting and the command-line value keeps overriding the value the test set on every later query.
  2. A ' inside a comment (-- don't use more threads) opens a string literal at line 303, which hides every , after it — so all remaining assignments of that SET are lost.
  3. A comment in the value becomes part of the parsed value. In clickhouse-cpp the value is only used for dialect_ (line 273), so SET dialect = 'clickhouse' -- back to SQL leaves dialect_ non-clickhouse and OtherDialect() (line 155) then wrongly suppresses FindOutputFormat for every following statement.

This is the clickhouse-cpp counterpart of ClickHouse/clickhouse-cs#754. The USE half of that report does not apply here: this shim does not parse USE at all — it keeps one native-protocol session and lets the server track the current database (see the comment at runner.h:39).

No test of the pinned allowlist changes its result today, but a new upstream test with a comment inside SET would fail for a shim cause rather than a client cause.

ClickHouse server version

26.10.4.207 (the version pinned in tests/clickhouse-test-runner/clickhouse-version). The reproduction below is a pure parsing unit test and needs no server.

Reproduction

Add to tests/clickhouse-test-runner/ut/args_ut.cpp, next to the existing TEST(ParseSetAssignments, Values):

TEST(ParseSetAssignments, Comments) {
    EXPECT_EQ((Settings{{"max_block_size", "100"}, {"max_threads", "1"}}),
              ParseSetAssignments("SET\n  max_block_size = 100,\n  -- one thread\n  max_threads = 1;"));
    EXPECT_EQ((Settings{{"max_block_size", "100"}, {"max_insert_threads", "1"}}),
              ParseSetAssignments("SET\n  -- don't use more threads\n  max_block_size = 100,\n  max_insert_threads = 1;"));
    EXPECT_EQ((Settings{{"format_tsv_null_representation", "NULL"}}),
              ParseSetAssignments("SET format_tsv_null_representation = 'NULL' /* text of NULL */;"));
}

Build and run:

tests/clickhouse-test-runner/scripts/build.sh
.build/tests/clickhouse-test-runner/clickhouse-test-runner-ut --gtest_filter=ParseSetAssignments.Comments

Actual output (three failures):

args_ut.cpp:131: Failure
  Expected: { ("max_block_size", "100"), ("max_threads", "1") }
  Actual:   { ("max_block_size", "100"), ("-- one thread\n  max_threads", "1") }

args_ut.cpp:133: Failure
  Expected: { ("max_block_size", "100"), ("max_insert_threads", "1") }
  Actual:   { ("-- don't use more threads\n  max_block_size", "100,\n  max_insert_threads = 1") }

args_ut.cpp:135: Failure
  Expected: { ("format_tsv_null_representation", "NULL") }
  Actual:   { ("format_tsv_null_representation", "'NULL' /* text of NULL */") }

Expected: the three settings parse as max_block_size=100, max_threads=1, max_block_size=100, max_insert_threads=1 and format_tsv_null_representation=NULL, exactly as clickhouse-client 26.10.4.207 understands them.

End-to-end effect (for case 1 and 2): with --max_threads=7 --max_insert_threads=7 on the command line and the first two SET statements above, the shim keeps sending max_threads=7 / max_insert_threads=7 as IMPORTANT settings, so SELECT getSetting('max_threads'), getSetting('max_insert_threads') returns 7 7 where clickhouse-client returns 1 1.

Suggested fix

In ParseSetAssignments (tests/clickhouse-test-runner/runner.cpp:278-316), handle comments in the split loop and in add:

  • In the loop over body, when the position starts a comment (--, #, /*), advance past it instead of scanning its characters — this is what already keeps a ' inside a comment from opening a literal in SkipWhitespaceAndComments (sql_text.cpp:93).
  • In add, skip leading comments before the setting name and strip trailing comments from the value before the TrimSpace / quote-stripping, so 'NULL' /* ... */ yields NULL.

SkipWhitespaceAndComments already exists in sql_text.cpp and can be reused for both.

Link

Relayed from ClickHouse/clickhouse-cs#754 — https://github.com/ClickHouse/clickhouse-cs/issues/754

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

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus ClickHouse/clickhouse-cpp

Alle Issues in ClickHouse/clickhouse-cpp

Ähnliche Issues

Weitere Issues zu C

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.