Repository navigation
[jdbc-v2] JavaCC parser: accept a heredoc cluster name and interval string - #3392
Open
polyglotAI-bot wants to merge 1 commit into
Open
polyglotAI-bot wants to merge 1 commit into
polyglotAI-bot wants to merge 1 commit into
Conversation
…tring `clusterClause` and the string form of `INTERVAL` accepted only a quoted string literal. A heredoc there (`ON CLUSTER $$c$$`, `INTERVAL $$1 day$$`), which the server accepts, made the parse fail: `ALTER TABLE ... ON CLUSTER` and `UPDATE ... ON CLUSTER` were classified as UNKNOWN, so `Statement.execute()` reported a result set, and an `INSERT ... VALUES` with a heredoc interval lost its values-list positions, so a batch was sent as one request per row. Both rules now accept `HEREDOC_LITERAL`. A heredoc cluster name is unwrapped with the new `ClickHouseSqlUtils.unwrapHeredoc()`: `unescape()` expects quote delimiters, and a heredoc has no escape sequences. Fixes: #3391 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Auto-approved by the AI review gate on 67314ee. Details in the approver's comment on this pull request.
AI review gate — auto-approved
History (latest 5 heads, newest first)
|
Client V2 CoverageCoverage Report
Class Coverage
|
JDBC V2 CoverageCoverage Report
Class Coverage
|
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
Closes #3391
The jdbc-v2 JavaCC grammar accepts a heredoc (
$$...$$,$tag$...$tag$) as a value since #3030, but two rules still accept only a quoted string literal. The server accepts a heredoc in both positions, so the driver failed to parse valid SQL:clusterClause(ALTER TABLE t ON CLUSTER $$c$$ ...,UPDATE t ON CLUSTER $$c$$ SET ...): the statement becameUNKNOWN, soStatement.execute()returnedtrueandgetUpdateCount()returned-1(falseand0forON CLUSTER 'c').INTERVAL '...'(now() - INTERVAL $$1 day$$): inINSERT ... VALUESthe values-list positions were dropped, soexecuteBatch()sent one request per row. A top-levelSELECT ... INTERVAL $$1 day$$wasUNKNOWN(the result-set flag is the same).Each of these statements also logged
WARN Failed to parse SQL.Changes
ClickHouseSqlParser.jj:clusterClauseand theINTERVALstring alternative accept<HEREDOC_LITERAL>.ClickHouseSqlUtils.unwrapHeredoc()(package-private): returns the body of a heredoc token.clusterClauseuses it for a heredoc cluster name.unescape()expects quote delimiters and does escape processing; a heredoc has no escape sequences.Positions not changed
I checked the other
<STRING_LITERAL>-only rules onmain(default JavaCC parser, server 26.10.4.207). I did not change them:CREATE/DROP/DELETE ... ON CLUSTER $$c$$andinput($$...$$): the classification is already correct. These rules do not useclusterClauseor recover from the error.INTO OUTFILE $$f$$: the classification is already correct. The server also rejectsINTO OUTFILEover HTTP (INTO_OUTFILE_NOT_ALLOWED).FROM INFILE $$f$$andCOMPRESSION $$m$$: the statement isUNKNOWN, but the server rejectsINSERT ... FROM INFILEover HTTP for both quote forms (Code 78: Query has infile and was send directly to server). jdbc-v2 does not read the file. The only change would be the parse warning.I can add these for symmetry if you prefer.
Tests
BaseSqlParserFacadeTest(throughSqlParserFacade, the parser entry point of the driver):heredocStatementsDP: 3INTERVALheredoc rows (all backends; ANTLR4 already accepts them).testHeredocClusterNameJavaCcOnly:ALTER/UPDATE ... ON CLUSTERwith a heredoc, plus the quoted form as contrast. JavaCC only, as fortestHeredocStatementsJavaCcOnly: the ANTLR4 grammars do not accept a heredoc cluster name yet.JavaCCParserTest.testClusterName: the extracted cluster name for an identifier, a quoted literal with'', a heredoc with''(no escape processing), and a tagged heredoc.Without the grammar change, the 8 new heredoc rows fail. With it, the parser tests pass for all three backends.
mvn -pl jdbc-v2 verifyon a local server 26.10.4.207: 2054 unit tests pass; 807 integration tests run with 1 failure,JdbcDataTypeTests.testIpAddressTypes, which resolveswww.example.comand my sandbox has no external DNS.Manual end-to-end check through
Statement/PreparedStatement:mainALTER TABLE t ON CLUSTER $$default$$ ADD COLUMN ...execute()=true, update count-1, WARNfalse,0executeBatch()of 3 rows,INSERT INTO t VALUES (?, now() - INTERVAL $$1 day$$)(async_insert=0)Compatibility
No public API change. The only behavior change is for statements that failed to parse before: they now get the same classification as the quoted form.
docs/features.mddoes not need a change.Checklist
history/latest/3391.md)🤖 Generated with Claude Code
Note
Low Risk
Parser-only change in jdbc-v2 with no public API changes; risk is limited to statement classification for SQL that previously parsed incorrectly.
Overview
Extends the jdbc-v2 JavaCC grammar so dollar-quoted strings (
$$...$$,$tag$...$tag$) are valid where ClickHouse already allows them but the driver previously only accepted quoted literals:ON CLUSTERcluster names andINTERVALstring operands.clusterClauseand theINTERVALbranch innestedExprnow accept<HEREDOC_LITERAL>. Cluster names use new package-privateClickHouseSqlUtils.unwrapHeredoc()(raw body, no quote escaping) instead ofunescape().Before, those statements often failed parsing and were classified as
UNKNOWN, which led to wrong JDBC behavior—for exampleStatement.execute()reporting a result set forALTER/UPDATE ... ON CLUSTER $$c$$, andexecuteBatch()onINSERT ... VALUES (?, now() - INTERVAL $$1 day$$)sending one INSERT per row instead of one batched statement.ANTLR4 grammars are unchanged. Tests cover
INTERVALheredocs across backends and JavaCC-onlyON CLUSTERheredoc classification and extracted cluster names.Reviewed by Cursor Bugbot for commit 67314ee. Bugbot is set up for automated code reviews on this repo. Configure here.