Repository navigation
[jdbc-v2] Accept lexer keywords (CLIENT, SCHEMA, MODEL, ...) as identifiers in the ANTLR4 grammar - #3458
Open
ricardo-costa-effy wants to merge 1 commit into
Conversation
64 keywords known to ClickHouseLexer (CLIENT, SCHEMA, MODEL, CONDITION, PAGE, ...) were missing from the parser's keyword rule, so an INSERT using one as an unquoted column failed to parse, its VALUES list was discarded and executeBatch() sent one INSERT per row. Add them to the keyword rule and test every one as a column name with all three parser backends. Fixes ClickHouse#3457 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3457.
64 keywords defined in
ClickHouseLexer.g4were missing from thekeywordrule inClickHouseParser.g4, so theANTLR4andANTLR4_PARAMS_PARSERbackends could not parse them as unquoted identifiers. Some are common column names:CLIENT,SCHEMA,MODEL,CONDITION,PAGE,CONFIG.For an
INSERT ... VALUESwith such a column, the parse error discarded theVALUESlist, andPreparedStatement#executeBatch()silently sent one INSERT per row instead of one multi-row INSERT.Changes
ClickHouseParser.g4: add the 64 missing tokens to thekeywordrule. Each is inserted at its alphabetical position; no existing line is moved or removed.NAN_SQLis left out because it is thenannumeric literal. None of the added tokens are inreserved_keywords.txt.BaseSqlParserFacadeTest, which runs for all three backends:testKeywordAsColumnName: each of the 64 keywords as an unquoted column (upper and lower case) inINSERT ... VALUESmust parse without errors, with one values group, valid values-list positions and the right argument count. It is also checked in aSELECT ... WHERE kw = ?.testKeywordColumnNameInBrokenInsert: negative case. A malformed INSERT with such a column must still report errors and no values list.history/latest/3457.md: change record.User-visible behavior / compatibility
JAVACCbackend.JAVACCis unaffected; it already accepted these names.Testing
mvn -pl jdbc-v2 test(unit tests, JDK 17): 2228 tests, 0 failures.testKeywordAsColumnNamefails for all 64 keywords onAntlr4ParserTestandAntlr4ParamsParserTest(128 failures) and passes onJavaCCParserTest.🤖 Generated with Claude Code
Note
Low Risk
Grammar-only expansion of identifier alternatives with regression tests; no changes to reserved keywords or JAVACC behavior, so previously valid SQL should remain accepted.
Overview
Fixes #3457 by extending the ANTLR4
ClickHouseParser.g4keywordrule with 64 lexer tokens (e.g.CLIENT,SCHEMA,MODEL,CONDITION,PAGE,CONFIG) that were not previously valid as unquoted identifiers. On ANTLR4 and ANTLR4_PARAMS_PARSER backends,INSERT ... VALUESstatements using those column names used to fail parsing, drop the VALUES span, and causePreparedStatement#executeBatch()to fall back to one INSERT per row instead of a single multi-row INSERT. JAVACC was already fine.BaseSqlParserFacadeTestaddstestKeywordAsColumnName(all 64 keywords in INSERT/SELECT) andtestKeywordColumnNameInBrokenInsert(malformed SQL still errors). Ahistory/latest/3457.mdnote documents the user-visible fix.Reviewed by Cursor Bugbot for commit c6541ad. Bugbot is set up for automated code reviews on this repo. Configure here.