[JDBC-v2] Fix parser to property handle keywords in aliases and table names #2725
[JDBC-v2] Fix parser to property handle keywords in aliases and table names #2725
Conversation
Client V2 CoverageCoverage Report
Class Coverage
|
JDBC V2 CoverageCoverage Report
Class Coverage
|
JDBC V1 CoverageCoverage Report
Class Coverage
|
Client V1 CoverageCoverage Report
Class Coverage
|
jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/BaseSqlParserFacadeTest.java
Show resolved
Hide resolved
jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/BaseSqlParserFacadeTest.java
Outdated
Show resolved
Hide resolved
jdbc-v2/src/main/antlr4/com/clickhouse/jdbc/internal/parser/antlr4/ClickHouseParser.g4
Show resolved
Hide resolved
jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/parser/javacc/ClickHouseSqlUtils.java
Outdated
Show resolved
Hide resolved
jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/parser/javacc/ClickHouseSqlUtils.java
Outdated
Show resolved
Hide resolved
jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/BaseSqlParserFacadeTest.java
Show resolved
Hide resolved
|
| (<WHEN> nestedExpr() <THEN> nestedExpr())+ (<ELSE> nestedExpr())? <END> | ||
| | LOOKAHEAD(2) <INTERVAL> (LOOKAHEAD(2) <STRING_LITERAL> | nestedExpr() interval()) | ||
| | columnExpr() | ||
| (LOOKAHEAD(2) <LBRACKET> anyExprList() <RBRACKET>)* |
There was a problem hiding this comment.
Inconsistent FLOATING_LITERAL LOOKAHEAD across three expression functions
Low Severity
The LBRACKET handling was moved outside the choice block identically in withExpr(), columnsExpr(), and nestedExpr(). However, the LOOKAHEAD({ getToken(1).kind == FLOATING_LITERAL }) guard was added before <FLOATING_LITERAL> in withExpr() and columnsExpr() but omitted in nestedExpr(). All three functions share the same structural pattern for this code block, so the inconsistent application of the fix is surprising and could confuse future maintainers.
Additional Locations (2)
|
|
||
| void settingsPart(): {} { | ||
| <SETTINGS> { token_source.addPosition(token); } settingExprList() | ||
| (LOOKAHEAD(1) <CHANGED>)? <SETTINGS> { token_source.addPosition(token); } (LOOKAHEAD(2) settingExprList())? |
There was a problem hiding this comment.
Optional settingExprList silently consumes bare SETTINGS keyword everywhere
Medium Severity
Making settingExprList() optional in settingsPart() enables SHOW CHANGED SETTINGS but also changes behavior in all other call sites (aliasExpr, anyNestedExpr, infilePart, insertStmt). Previously, a bare SETTINGS without key=value pairs would produce a parse error, acting as a guard against incorrect consumption. Now SETTINGS is silently consumed everywhere, even in contexts like INSERT INTO t SETTINGS VALUES (1) where the old parser would correctly error and fall back.





Summary
INin select statementDESCRIBE (SELECT)Closes #2718
Checklist
Delete items not relevant to your PR:
Note
Medium Risk
Touches core SQL parsing/statement classification and keyword handling, which can change how queries are tokenized and how table/alias names are extracted; covered by added tests but regressions could affect many query shapes.
Overview
Fixes JDBC v2 SQL parsing around identifiers that collide with ClickHouse keywords.
Updates both the ANTLR4 and JavaCC grammars to recognize a much larger keyword set and to selectively allow non-reserved keywords as unquoted aliases/table names via a centralized
ALLOWED_KEYWORD_ALIASESlist (plus new parsing forDESCRIBE (SELECT ...), optionalCHANGED SETTINGS, saferINSERT INTO FUNCTIONlookahead, and bracketed array access within expressions).Adds resource-backed keyword lists and new integration/unit tests to validate allowed keyword aliases against
system.keywords, and to ensure keyword-based table names/aliases and new statement forms parse correctly.Written by Cursor Bugbot for commit a4ca320. This will update automatically on new commits. Configure here.