Core SQL test harness: the shim does not skip comments inside SET and USE statements

Aperta Adatta ai principianti
#754 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
70/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp, sql
Ambito
testing, tooling

Direzione di ricerca

Inizia in tests/clickhouse-test-runner/ClickHouse.Driver.TestRunner/Runner.cs: ParseSetAssignments (intorno alle righe 107-145) rimuove i commenti solo prima di SET, e ParseUseDatabase (intorno alle righe 78-80) li mantiene e ferma DATABASE solo in corrispondenza di uno spazio. Compila lo shim con tests/clickhouse-test-runner/scripts/build.sh e riproduci con i set.sql/use.sql forniti sia su http sia su tcp prima di modificare. Fatto significa che lo shim stampa lo stesso output di clickhouse-client per quei passaggi, incluso il commento don't e la tabulazione dopo USE DATABASE.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

tests
Describe the bug

The shim of the core SQL test harness (tests/clickhouse-test-runner) reads the SET and USE statements of a test to follow the session state, as clickhouse-client does. A comment inside such a statement gives a result that is different from clickhouse-client, over both protocols (http, tcp):

  • SET: a setting after a comment keeps its command-line value (--max_threads=7) on each later query, so it overrides the value that the test set. A comment with a ' (-- don't) does this for all the assignments after it.
  • SET: a comment in the value of an output setting (format_tsv_null_representation) becomes part of the value that the shim prints.
  • USE: a comment after USE, or a tab or a newline after USE DATABASE, stops the test with cannot read the database name.

No test of the pinned suite changes its result today: at v26.10.4.207, only 04277_parallel_replicas_join_dp_reorder (not in the allowlist) has a comment inside SET, and the shim does not track the setting after that comment. A new upstream test with this form fails for a shim cause.

Steps to reproduce
  1. Start the pinned server (README, step 1) and build the shim: tests/clickhouse-test-runner/scripts/build.sh.
  2. tests/clickhouse-test-runner/.bin/clickhouse-client --max_threads=7 --max_insert_threads=7 < set.sql
  3. tests/clickhouse-test-runner/.bin/clickhouse-client < use.sql
  4. tests/clickhouse-test-runner/.bin/clickhouse-client --query "$(printf 'USE DATABASE\trepro_db')"

Run each step again with CLICKHOUSE_TEST_RUNNER_PROTOCOL=tcp, and with clickhouse-client in the server container.

Expected behaviour

The output of clickhouse-client 26.10.4.207 for the same steps:

step 2: 1	1	NULL
step 3: repro_db
step 4: no output, exit code 0
Code example

set.sql:

SET
  max_block_size = 100,
  -- one thread
  max_threads = 1;
SET
  -- don't use more threads
  max_block_size = 100,
  max_insert_threads = 1;
SET format_tsv_null_representation = 'NULL' /* text of NULL */;
SELECT getSetting('max_threads'), getSetting('max_insert_threads'), NULL;

use.sql:

CREATE DATABASE IF NOT EXISTS repro_db;
USE /* the test database */ repro_db;
SELECT currentDatabase();
Error log

Shim output, the same over http and tcp:

step 2: 7	7	'NULL' /* text of NULL */
step 3: Error: InvalidOperationException: clickhouse-test-runner: cannot read the database name of "USE /* the test database */ repro_db;"
step 4: Error: InvalidOperationException: clickhouse-test-runner: cannot read the database name of "USE DATABASE	repro_db"
Root cause
  • tests/clickhouse-test-runner/ClickHouse.Driver.TestRunner/Runner.cs:107-145 (ParseSetAssignments): it skips comments only before SET, then splits the rest on , and = with the comments in place. A comment becomes part of the next setting name or of the value, so AfterSuccess (line 267) does not remove the command-line setting. A ' in a comment starts a string literal at line 130, which hides the commas after it.
  • Runner.cs:78-80 (ParseUseDatabase): it keeps comments in the database name, and it finds the end of DATABASE only at a space.

The fix is in these two functions of the shim only.

Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.

Configuration
Environment
  • Client version: main at 9267d729 (the shim is not in the package)
  • .NET version: net10.0 (SDK 10.0.404)
  • OS: Linux (container)
ClickHouse server
  • ClickHouse Server version: 26.10.4.207
  • ClickHouse Server non-default settings, if any: none

Classification: impact: none · area: Docs & project (core SQL test harness)


Found by automated analysis (Polyglot AI) while working on ClickHouse/clickhouse-connect#1223. Verified against a live server.

Lingua principale
C#
Stelle
101
Fork
28
Merge medio
2g 11h
PR unite (30g)
30

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ClickHouse/clickhouse-cs

Tutte le issue di ClickHouse/clickhouse-cs

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.