Repository navigation
Description
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 afterUSE, or a tab or a newline afterUSE DATABASE, stops the test withcannot 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
- Start the pinned server (README, step 1) and build the shim:
tests/clickhouse-test-runner/scripts/build.sh. tests/clickhouse-test-runner/.bin/clickhouse-client --max_threads=7 --max_insert_threads=7 < set.sqltests/clickhouse-test-runner/.bin/clickhouse-client < use.sqltests/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 beforeSET, then splits the rest on,and=with the comments in place. A comment becomes part of the next setting name or of the value, soAfterSuccess(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 ofDATABASEonly 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:
mainat 9267d72 (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.
Activity