Skip to content

jdbc-v2: JavaCC parser does not accept a heredoc as an ON CLUSTER name or an INTERVAL string #3391

Open

Description

@polyglotAI-bot

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:

  1. ALTER TABLE t ON CLUSTER $$c$$ ... and UPDATE t ON CLUSTER $$c$$ SET ...: Statement.execute() returns true and getUpdateCount() returns -1. With ON CLUSTER 'c' they return false and 0.
  2. INSERT INTO t VALUES (?, now() - INTERVAL $$1 day$$): PreparedStatement.executeBatch() sends one request for each row instead of one request for the batch.
  3. Each of these statements logs WARN Failed to parse SQL.... A top-level SELECT 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

  1. Connect with jdbc-v2 to a server that has a cluster named default (default parser).
  2. Run stmt.execute("ALTER TABLE t ON CLUSTER $$default$$ ADD COLUMN IF NOT EXISTS c Int").
  3. 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, main at 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions