[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
|
|
| log.error("Failed to load keywords from " + resource, e); | ||
| } | ||
| return keywords; | ||
| } |
There was a problem hiding this comment.
Resource loading failure breaks keyword alias parsing
High Severity
The loadKeywords() method silently returns an empty set if allowed_keyword_aliases.txt cannot be loaded, causing ALLOWED_ALIAS_KEYWORDS to be empty. This breaks the aliasIdentifier() function at line 931, where isAllowedAlias() will always return false. As a result, valid SQL queries using keywords as aliases will fail to parse. The error is only logged (line 71), making this difficult to diagnose in production when queries that should work start failing.
| } | ||
| Assert.assertEquals(stmt5.getArgCount(), 1, "Should have 1 parameter for: " + sql5); | ||
| if (!stmt2.getTable().equalsIgnoreCase(keyword)) { | ||
| failedKeywords.add(keyword + " (test: INSERT INTO " + keyword + " VALUES (?)) table name check failed"); |
There was a problem hiding this comment.
Test validates wrong statement's table name
Medium Severity
The test validates stmt2.getTable() instead of stmt5.getTable() when checking the INSERT statement at line 887. This checks the table name extracted from the SELECT statement (line 879) instead of the INSERT statement being tested, causing the validation to fail incorrectly when the INSERT statement is tested after the SELECT statement in a different iteration or context where table names might differ.
| BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { | ||
|
|
||
| if (is == null) { | ||
| return keywords; |
There was a problem hiding this comment.
Null resource causes NullPointerException in test
Medium Severity
The BufferedReader is created in the try-with-resources declaration using a null InputStream before the null check executes. When the resource file cannot be found, getResourceAsStream() returns null, and new InputStreamReader(is, StandardCharsets.UTF_8) at line 806 throws NullPointerException before reaching the null check at line 808. The test should check for null before creating the InputStreamReader, like the implementation in StatementSQLTest.loadKeywordsFromResource() at lines 116-120.





Summary
INin select statementDESCRIBE (SELECT)Closes #2718
Checklist
Delete items not relevant to your PR:
Note
Medium Risk
Touches core SQL parsing logic and keyword classification, which can change how statements are recognized and parameters/tables extracted; however changes are mostly additive and covered by new tests.
Overview
Improves parser handling of keywords used as identifiers by expanding the ANTLR
keyword/keywordForAliaslists and updating JavaCC alias parsing to only treat a curated allowlist of keywords as valid aliases (loaded from a new resource file).Extends JavaCC statement parsing for additional ClickHouse syntax, including
DESCRIBE (subquery)/DESCRIBE TABLE (subquery),SHOW CHANGED SETTINGS, optional/emptySETTINGSclauses, and more robust array indexing in expressions.Adds new keyword resource lists (allowed alias keywords, allowed table-name keywords, reserved keywords, and a master keyword list) and adds/extends tests to validate keyword-as-table-name/alias behavior and the new statement forms (with one integration keyword probe test added but disabled).
Written by Cursor Bugbot for commit c6a6ad7. This will update automatically on new commits. Configure here.