Repository navigation
Description
Description
tests/clickhouse-client (the clickhouse-client shim used to run the ClickHouse core SQL test suite) splits a --multiquery script into statements with Main.splitQueries (tests/clickhouse-client/src/main/java/com/clickhouse/client/cli/Main.java:472-530).
That splitter tracks ', ", ` and backslash escapes, but it does not know about SQL comments. Two consequences, both of which make a correct .sql test file fail for a shim-side reason:
- An apostrophe inside a
--comment opens a string literal.-- don't use more threadsflipsinSingleQuotetotrue, so every following;is treated as being inside a string and no longer splits. All remaining statements are glued into one query, and the server rejects it withMulti-statements are not allowed(code 62). The same happens with a"or a`in a comment. - A
;inside a comment splits the statement.SELECT 1 /* a ; b */ + 1is cut in half, and the first half is sent with an unclosed/*, so the server answersMultiline comment is not closed(code 62).
Real clickhouse-client skips -- and /* */ comments while lexing, so neither case is an error there.
This is the Java counterpart of ClickHouse/clickhouse-cs#754. The exact symptoms reported there (session SET/USE tracking) do not apply — this shim does not parse SET or USE at all, it sends them to the server verbatim — but the root cause is the same: the shim lexes SQL text without skipping comments, and a ' in a comment hides the delimiters after it.
ClickHouse server version
26.10.4.207 (verified against a running server over HTTP).
Reproduction
Build the shim and run it against a local server. Note: the module pins clickhouse-java.version=0.9.6-SNAPSHOT while the tree is 0.12.0-rc1-SNAPSHOT, so the version has to be overridden to build it today.
mvn -q -DskipTests -pl clickhouse-jdbc -am install
cd tests/clickhouse-client
mvn -q package -DskipTests -Dclickhouse-java.version=0.12.0-rc1-SNAPSHOTCase 1 — apostrophe in a -- comment
printf "SELECT 1;\n-- don't\nSELECT 2;\nSELECT 3\n" \
| java -jar target/clickhouse-client-cli-1.0.0.jar --host localhost --port 8123 --multiqueryExpected (what clickhouse-client prints):
1
2
3
Actual:
1
Error: Code: 62. DB::Exception: Syntax error (Multi-statements are not allowed): failed at position 18 (end of query) (line 2, col 9): ; SELECT 3. . (SYNTAX_ERROR)
SELECT 2;\nSELECT 3 was kept as a single statement because the ' in don't opened a string literal that never closes.
Case 2 — semicolon in a /* */ comment
printf "SELECT 1 /* a ; b */ + 1;\nSELECT 2\n" \
| java -jar target/clickhouse-client-cli-1.0.0.jar --host localhost --port 8123 --multiqueryExpected:
2
2
Actual:
Error: Code: 62. DB::Exception: Multiline comment is not closed: Syntax error: failed at position 10 (/* a): /* a. . (SYNTAX_ERROR)
(Both runs above were executed through mvn exec:java -Dexec.mainClass=com.clickhouse.client.cli.Main with the same arguments in this environment; the java -jar form is equivalent.)
Impact
Any upstream core SQL test whose script contains an apostrophe in a -- comment, or a ; inside any comment, fails in the shim rather than in the client under test. This matters for the nightly core SQL test run being set up in #3389, where such a failure is indistinguishable from a real client regression.
Suggested fix
In Main.splitQueries (tests/clickhouse-client/src/main/java/com/clickhouse/client/cli/Main.java:472), add comment states to the lexer alongside the existing quote states:
- when not inside a quote,
--starts a line comment that ends at\n; - when not inside a quote,
/*starts a block comment that ends at*/; - inside either comment, no character may change quote state or split a statement.
Comment text should still be appended to current so the statement is sent unchanged to the server.
Link
Relayed from ClickHouse/clickhouse-cs#754 (central tracking: https://github.com/ClickHouse/integrations-ai-playground/issues/737).
Activity