Skip to content

[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
ClickHouse:mainfrom
ricardo-costa-effy:fix/3457-antlr4-keyword-identifiers
Open

ricardo-costa-effy wants to merge 1 commit into
ClickHouse:mainfrom
ricardo-costa-effy:fix/3457-antlr4-keyword-identifiers

Conversation

@ricardo-costa-effy

@ricardo-costa-effy ricardo-costa-effy commented Nov 27, 2026 •

Copy link
Copy Markdown

Summary

Fixes #3457.

64 keywords defined in ClickHouseLexer.g4 were missing from the keyword rule in ClickHouseParser.g4, so the ANTLR4 and ANTLR4_PARAMS_PARSER backends could not parse them as unquoted identifiers. Some are common column names: CLIENT, SCHEMA, MODEL, CONDITION, PAGE, CONFIG.

For an INSERT ... VALUES with such a column, the parse error discarded the VALUES list, and PreparedStatement#executeBatch() silently sent one INSERT per row instead of one multi-row INSERT.

Changes

  • ClickHouseParser.g4: add the 64 missing tokens to the keyword rule. Each is inserted at its alphabetical position; no existing line is moved or removed. NAN_SQL is left out because it is the nan numeric literal. None of the added tokens are in reserved_keywords.txt.
  • BaseSqlParserFacadeTest, which runs for all three backends:
    • testKeywordAsColumnName: each of the 64 keywords as an unquoted column (upper and lower case) in INSERT ... VALUES must parse without errors, with one values group, valid values-list positions and the right argument count. It is also checked in a SELECT ... 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

  • Statements that failed to parse with the ANTLR4 backends now parse, and batches of such INSERTs are sent as one INSERT, as with the default JAVACC backend.
  • No statement that parsed before is rejected now. Rules only gain alternatives, and no other rule changed.
  • JAVACC is unaffected; it already accepted these names.

Testing

  • mvn -pl jdbc-v2 test (unit tests, JDK 17): 2228 tests, 0 failures.
  • Without the grammar change, testKeywordAsColumnName fails for all 64 keywords on Antlr4ParserTest and Antlr4ParamsParserTest (128 failures) and passes on JavaCCParserTest.
  • Integration tests were not run locally.

🤖 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.g4 keyword rule 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 ... VALUES statements using those column names used to fail parsing, drop the VALUES span, and cause PreparedStatement#executeBatch() to fall back to one INSERT per row instead of a single multi-row INSERT. JAVACC was already fine.

BaseSqlParserFacadeTest adds testKeywordAsColumnName (all 64 keywords in INSERT/SELECT) and testKeywordColumnNameInBrokenInsert (malformed SQL still errors). A history/latest/3457.md note 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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[jdbc-v2] ANTLR4 parser: keyword column names (CLIENT, SCHEMA, MODEL, ...) break INSERT parsing, executeBatch falls back to one INSERT per row

1 participant