Repository navigation
Description
Description
The jdbc-v2 JavaCC parser (the default, jdbc_sql_parser=JAVACC) does not accept a heredoc string ($$...$$, $tag$...$tag$) in two positions: the cluster name in ON CLUSTER, and the string form of INTERVAL '...'. The server accepts a heredoc in both positions. The driver then gives these results:
ALTER TABLE t ON CLUSTER $$c$$ ...andUPDATE t ON CLUSTER $$c$$ SET ...:Statement.execute()returnstrueandgetUpdateCount()returns-1. WithON CLUSTER 'c'they returnfalseand0.INSERT INTO t VALUES (?, now() - INTERVAL $$1 day$$):PreparedStatement.executeBatch()sends one request for each row instead of one request for the batch.- Each of these statements logs
WARN Failed to parse SQL.... A top-levelSELECT now() + INTERVAL $$1 day$$logs it too.
Out of scope here: the ANTLR4 parsers (jdbc_sql_parser=ANTLR4, ANTLR4_PARAMS_PARSER) and the clickhouse-jdbc v1 parser. Positions where the classification is already correct or where the server rejects the statement over HTTP (INTO OUTFILE, FROM INFILE, input(...)) are also out of scope.
Steps to reproduce
- Connect with jdbc-v2 to a server that has a cluster named
default(default parser). - Run
stmt.execute("ALTER TABLE t ON CLUSTER $$default$$ ADD COLUMN IF NOT EXISTS c Int"). - Compare with
stmt.execute("ALTER TABLE t ON CLUSTER 'default' ADD COLUMN IF NOT EXISTS b Int").
Error Log or Exception StackTrace
WARN ClickHouseSqlParser - Failed to parse SQL. If you believe the SQL is valid, please feel free to open an issue on GitHub with this warning. Enable DEBUG logging for details.
Expected Behaviour
A heredoc cluster name or interval string gives the same result as the quoted form: execute() returns false with update count 0, the batch insert is sent as one request, and no parse warning is logged.
Code Example
try (Connection conn = DriverManager.getConnection(url, props); Statement stmt = conn.createStatement()) {
stmt.execute("CREATE TABLE t (a Int) ENGINE = MergeTree ORDER BY a");
System.out.println(stmt.execute("ALTER TABLE t ON CLUSTER 'default' ADD COLUMN IF NOT EXISTS b Int")); // false
System.out.println(stmt.execute("ALTER TABLE t ON CLUSTER $$default$$ ADD COLUMN IF NOT EXISTS c Int")); // true
System.out.println(stmt.getUpdateCount()); // -1
}Root cause
Since #3029, the JavaCC grammar accepts a heredoc as a value. Two rules still accept only a quoted string literal: clusterClause (used by ALTER TABLE ... ON CLUSTER and UPDATE ... ON CLUSTER) and the string form of INTERVAL '...'. When the parse fails, the ON CLUSTER statements are classified as UNKNOWN, and the INSERT loses its values-list positions.
Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Configuration
Client Configuration
// default properties; jdbc_sql_parser = JAVACC (default)Environment
- Cloud
- Client version: jdbc-v2,
mainat 7506301 - Server version: 26.10.4.207
Found by automated analysis (Polyglot AI) while working on another issue. Verified against a live server. Shortened on 2026-11-20: the edit history has the first version.
Activity