Skip to content

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

Open

Description

@polyglotAI-bot

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 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions