jdbc-v2: ANTLR4 parsers do not accept a heredoc as an ON CLUSTER name or a column comment
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 83/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- java
研究方向
從 jdbc-v2/src/main/antlr4/com/clickhouse/jdbc/internal/parser/antlr4/ClickHouseParser.g4 開始,重點關注 clusterClause 和 issue 中提到的欄位註解規則。閱讀現有的 literal 規則和 parser 測試,接著新增 heredoc 叢集名稱和註解的案例,同時保留加引號的形式。這些案例中的 ANTLR4 parser 傳回預期的更新結果時,即代表完成;issue 指出 BaseSqlParserFacadeTest 是共用的測試入口。
由索引模型根據 Issue 內容生成。
描述
Description
With jdbc_sql_parser=ANTLR4 or ANTLR4_PARAMS_PARSER, jdbc-v2 does not accept a heredoc ($$...$$, $tag$...$tag$) in two positions where the server accepts it:
- the cluster name in
ON CLUSTER - the column comment (
COMMENTin a column definition, andALTER TABLE ... COMMENT COLUMN)
In a statement with ON CLUSTER, the driver then returns the server's distributed-DDL status table as a ResultSet. Statement.execute() and PreparedStatement.execute() return true, getUpdateCount() returns -1, and getResultSet() returns 1 status row (host, port, status, error, num_hosts_remaining, num_hosts_active). With ON CLUSTER default or ON CLUSTER 'default', the same statement returns false and 0.
Seen with $$default$$ and $tag$default$tag$, with both parsers, for CREATE TABLE, ALTER TABLE ... ADD COLUMN, ALTER TABLE ... UPDATE, ALTER TABLE ... DELETE, OPTIMIZE TABLE ... FINAL, RENAME TABLE, TRUNCATE TABLE and DROP TABLE. A heredoc column comment with ON CLUSTER 'default' has the same effect: ALTER TABLE t ON CLUSTER 'default' COMMENT COLUMN a $$x$$, and CREATE TABLE t ON CLUSTER 'default' (a Int COMMENT $$x$$) ....
PreparedStatement.getMetaData() before execution sends DESC (ALTER TABLE ... ON CLUSTER $$default$$ ...). The server rejects it (Code: 62), and the driver logs a WARN with a stack trace. With the quoted form, no request is sent.
Without ON CLUSTER, the parse error also occurs, but execute() returns false and 0, because the server sends no result. The server runs all of these statements correctly in both forms.
Steps to reproduce
- Connect with jdbc-v2 and
jdbc_sql_parser=ANTLR4(orANTLR4_PARAMS_PARSER) to a server that has a cluster nameddefault. - Run
stmt.execute("CREATE TABLE t ON CLUSTER $$default$$ (a Int) ENGINE = MergeTree ORDER BY a"). - Compare with
stmt.execute("CREATE TABLE t2 ON CLUSTER 'default' (a Int) ENGINE = MergeTree ORDER BY a").
Error Log or Exception StackTrace
execute() logs no error (the parse error is at DEBUG only). PreparedStatement.getMetaData() logs:
WARN PreparedStatementImpl - Failed to resolve result-set metadata for prepared statement; falling back to untyped metadata
com.clickhouse.client.api.ServerException: Code: 62. DB::Exception: Syntax error: failed at position 13 (TABLE): TABLE p3 ON CLUSTER $$default$$ UPDATE b = NULL WHERE 1). ...
Expected Behaviour
A heredoc cluster name or column comment gives the same result as the quoted form: execute() returns false with update count 0, and getMetaData() sends no DESC request.
Code Example
Properties props = new Properties();
props.setProperty("user", "default");
props.setProperty("password", "...");
props.setProperty("jdbc_sql_parser", "ANTLR4"); // or ANTLR4_PARAMS_PARSER
try (Connection conn = DriverManager.getConnection("jdbc:clickhouse://localhost:8123/default", props);
Statement stmt = conn.createStatement()) {
System.out.println(stmt.execute("CREATE TABLE t1 ON CLUSTER 'default' (a Int) ENGINE = MergeTree ORDER BY a")); // false
System.out.println(stmt.getUpdateCount()); // 0
System.out.println(stmt.execute("CREATE TABLE t2 ON CLUSTER $$default$$ (a Int) ENGINE = MergeTree ORDER BY a")); // true
System.out.println(stmt.getUpdateCount()); // -1
}
Root cause
jdbc-v2/src/main/antlr4/com/clickhouse/jdbc/internal/parser/antlr4/ClickHouseParser.g4:279isclusterClause : ON CLUSTER (identifier | STRING_LITERAL), and the column comment rules (lines 73, 332 and 335) also nameSTRING_LITERAL. The lexer tokenHEREDOC_LITERAL(since #3031) is accepted only byliteral(lines 1203-1208).- After a parse error,
parsedStatement()andparsePreparedStatement()sethasResultSet=true(SqlParserFacade.java:254-256,264-265). Soexecute()(StatementImpl.java:565,PreparedStatementImpl.java:309) uses the query path, andgetMetaData()(PreparedStatementImpl.java:423) sendsDESC (...).
The fix is in ClickHouseParser.g4 only: no listener reads the cluster name or the comment.
Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Related
- #3391: same defect in the default
JAVACCparser (fix in #3392).
Configuration
Client Configuration
// jdbc_sql_parser = ANTLR4 or ANTLR4_PARAMS_PARSER; other properties default
Environment
- Cloud
- Client version: jdbc-v2
mainat 75063012b (0.12.0-rc1-SNAPSHOT) - Language version: Java 17.0.21
- OS: Linux (Docker)
ClickHouse Server
- ClickHouse Server version: 26.10.4.207
- ClickHouse Server non-default settings, if any: one-node cluster
defaultwith Keeper (forON CLUSTER) CREATE TABLEstatements for tables involved: in the examples above- Sample data for all these tables: not necessary
Classification: impact: none · area: Queries (ANTLR4 SQL parser)
Found by automated analysis (Polyglot AI) while working on #3391. Verified against a live server. Shortened on 2026-11-20: the edit history has the first version.
- 主要語言
- Java
- 星號
- 1.6k
- 分支
- 657
- 平均合併
- 2 天 6 小時
- 30 天內合併 PR
- 36
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
ClickHouse/clickhouse-java 的其他 Issue
-
api-diagnostics bug jdbc
難度 2/5 1-3 小時 新手友好度 75/100
ClickHouse/clickhouse-java#3464 ·
維護者通常 1 天內回覆
-
tests
難度 2/5 1-3 小時 新手友好度 76/100
ClickHouse/clickhouse-java#3452 ·
維護者通常 1 天內回覆
-
bug jdbc performance queries sql-parser
難度 2/5 1-3 小時 新手友好度 77/100
ClickHouse/clickhouse-java#3451 ·
維護者通常 1 天內回覆
-
bug jdbc legacy queries
難度 2/5 1-3 小時 新手友好度 70/100
ClickHouse/clickhouse-java#3444 ·
維護者通常 1 天內回覆
-
api-diagnostics bug client jdbc
難度 2/5 1-3 小時 新手友好度 76/100
ClickHouse/clickhouse-java#3439 · 1 則留言 ·
維護者通常 1 天內回覆
查看 ClickHouse/clickhouse-java 的全部 Issue
相似的 Issue
-
[BUG] Nightly Build JDK 17: latest-frameworks job red since 2026-11-28 — quarkiverse-langchain4j 2.0.0 pins Quarkus 4.0.0, which requires Java 21可能已有人在做 @uhhgxg 今天認領。 未關閉
難度 1/5 1 小時以內 新手友好度 95/100
langchain4j/langchain4j#7344 ·
維護者通常 1 天內回覆
-
documentation good first issue
難度 2/5 1-3 小時 新手友好度 75/100
cristianEncarnacion/ferroreport#149 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 60/100
quelea-projection/Quelea#749 ·
維護者通常 1 天內回覆
-
free_port can hand one port to two callers, so the fixed-port http tests fail in parallel runs可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 92/100
erkamyaman/rust-anything#963 ·
維護者通常 1 天內回覆
-
難度 2/5 半天 新手友好度 76/100