Core SQL test harness: ParseSetAssignments does not skip comments inside SET
维护者通常 1 天内回复
评估
调研方向
从 tests/clickhouse-test-runner/runner.cpp 中的 ParseSetAssignments(第 278-316 行)开始,尤其是拆分循环和 add;复用 tests/clickhouse-test-runner/sql_text.cpp 中的 SkipWhitespaceAndComments。将 ParseSetAssignments.Comments 用例添加到 tests/clickhouse-test-runner/ut/args_ut.cpp,然后用 tests/clickhouse-test-runner/scripts/build.sh 构建,并用 --gtest_filter=ParseSetAssignments.Comments 运行 runner 单元测试。完成意味着三个设置解析后名称或值中不含注释文本,并且注释中的 ' 不再隐藏后续赋值。
由索引模型根据 Issue 内容生成。
描述
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:
- 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. - 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 thatSETare lost. - A comment in the value becomes part of the parsed value. In clickhouse-cpp the value is only used for
dialect_(line 273), soSET dialect = 'clickhouse' -- back to SQLleavesdialect_non-clickhouseandOtherDialect()(line 155) then wrongly suppressesFindOutputFormatfor 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 inSkipWhitespaceAndComments(sql_text.cpp:93). - In
add, skip leading comments before the setting name and strip trailing comments from the value before theTrimSpace/ quote-stripping, so'NULL' /* ... */yieldsNULL.
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
- 主要语言
- C
- 星标
- 388
- 派生
- 220
- 平均合并
- 1 天 25 分钟
- 30 天内合并 PR
- 16
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ClickHouse/clickhouse-cpp 的其他 Issue
-
bug data-types
难度 2/5 1-3 小时 新手友好度 76/100
ClickHouse/clickhouse-cpp#645 ·
维护者通常 1 天内回复
-
bug queries
难度 2/5 1-3 小时 新手友好度 79/100
ClickHouse/clickhouse-cpp#644 ·
维护者通常 1 天内回复
-
bug data-types native-format
难度 2/5 1-3 小时 新手友好度 82/100
ClickHouse/clickhouse-cpp#643 ·
维护者通常 1 天内回复
-
bug connectivity native-protocol
难度 2/5 1-3 小时 新手友好度 78/100
ClickHouse/clickhouse-cpp#638 ·
维护者通常 1 天内回复
-
Enum type parsing: duplicate ordinals (Enum8('a' = 1, 'b' = 1)) and duplicate labels (Enum8('a' = 1, 'a' = 2)) are silently accepted and lose a member可能已有人在做 @SBNREX 于 19 天前认领。 未关闭bug data-types native-format
难度 2/5 1-3 小时 新手友好度 75/100
ClickHouse/clickhouse-cpp#607 · 1 条评论 ·
维护者通常 1 天内回复
查看 ClickHouse/clickhouse-cpp 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
-
type:feature
难度 2/5 1-3 小时 新手友好度 78/100
google-coral/coralnpu#175 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复