Skip to content

[jdbc-v2] Keyword test fails on CH 26.11 (SEGMENTS, SHARDS); ANTLR4 grammar does not accept shards as an identifier #3428

In review

Description

@polyglotAI-bot

Description

Since the clickhouse/clickhouse-server:latest image moved to 26.11 (2026-11-25), StatementSQLTest.testAllowedKeywordAliasesMatchSystemKeywords fails on main in the checks "JDBC driver + CH latest" and "jdbc-v2 + CH cluster latest" (run on f01962a23). The server has two new non-reserved keywords, SEGMENTS and SHARDS.

The default parser (JAVACC) parses both words as identifiers. The ANTLR4 and ANTLR4_PARAMS_PARSER parsers (jdbc_sql_parser) report a syntax error for each statement that uses shards as an alias, column, or table name, with all server versions. In the cases tested, the driver recovers from the error and the results are correct. One visible effect: with beta.row_binary_for_simple_insert=true, INSERT INTO shards VALUES (?) does not use the RowBinary writer. segments parses without errors in all three parsers.

Steps to reproduce

  1. Run StatementSQLTest#testAllowedKeywordAliasesMatchSystemKeywords against server 26.11.2.4.
  2. Run the program in "Code Example". It calls the three parsers directly.
  3. Append "SEGMENTS", "SHARDS" to ALLOWED_KEYWORD_ALIASES (the usual fix, as in [jdbc-v2] Add RETURNING, SHARED keywords and Elasticsearch engine for ClickHouse HEAD #3274), and run the unit tests Antlr4ParserTest and Antlr4ParamsParserTest.

Error Log or Exception StackTrace

Step 1:

StatementSQLTest.testAllowedKeywordAliasesMatchSystemKeywords:147 New keywords found in system.keywords (non-reserved) that must be added to ALLOWED_KEYWORD_ALIASES or reserved_keywords.txt: ["SEGMENTS", "SHARDS"] expected [true] but found [false]

Step 2:

JAVACC: SELECT 1 AS shards -> hasErrors=false, table=unknown
JAVACC: INSERT INTO shards VALUES (?) -> hasErrors=false, table=shards
JAVACC: SELECT 1 AS segments -> hasErrors=false, table=unknown
ANTLR4: SELECT 1 AS shards -> hasErrors=true, table=null
ANTLR4: INSERT INTO shards VALUES (?) -> hasErrors=true, table=VALUES
ANTLR4: SELECT 1 AS segments -> hasErrors=false, table=null
ANTLR4_PARAMS_PARSER: SELECT 1 AS shards -> hasErrors=true, table=null
ANTLR4_PARAMS_PARSER: INSERT INTO shards VALUES (?) -> hasErrors=true, table=VALUES
ANTLR4_PARAMS_PARSER: SELECT 1 AS segments -> hasErrors=false, table=null

Step 3 (the same failure in Antlr4ParamsParserTest):

Antlr4ParserTest>BaseSqlParserFacadeTest.testKeywordAliasesAsTableNames:1551 The following keywords caused parsing errors:
SHARDS (test: SELECT * FROM table AS SHARDS)

Expected Behaviour

The server accepts both words as identifiers:

$ curl -u default:... --data-binary 'SELECT 1 AS shards, 2 AS segments FORMAT TSVWithNames' http://localhost:8123/
shards	segments
1	2

The keyword test passes on 26.11, and all three parsers parse SELECT 1 AS shards and INSERT INTO shards VALUES (?) with no errors and with the table shards.

Root cause

  • ALLOWED_KEYWORD_ALIASES (jdbc-v2/.../javacc/ClickHouseSqlUtils.java:86, the last // Appended block) does not have SEGMENTS and SHARDS.
  • The ANTLR4 lexer has the token SHARDS (ClickHouseLexer.g4:318), but the parser rules keyword and keywordForAlias (ClickHouseParser.g4:1476 and :1743, after SHARD) do not list it, so shards cannot be an identifier or an alias.

The fix is two list entries and one line in each of the two grammar rules.
Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.

Code Example

Reproduction program (Java, 20 lines, in jdbc-v2/src/test/java)
package repro;

import com.clickhouse.jdbc.internal.JdbcConfiguration;
import com.clickhouse.jdbc.internal.ParsedPreparedStatement;
import com.clickhouse.jdbc.internal.SqlParserFacade;
import java.util.Properties;

public class ShardsKeywordRepro {
    public static void main(String[] args) throws Exception {
        for (String name : new String[]{"JAVACC", "ANTLR4", "ANTLR4_PARAMS_PARSER"}) {
            SqlParserFacade p = SqlParserFacade.getParser(name,
                    new JdbcConfiguration("jdbc:ch:http://localhost:8123", new Properties()));
            for (String sql : new String[]{"SELECT 1 AS shards", "INSERT INTO shards VALUES (?)",
                    "SELECT 1 AS segments"}) {
                ParsedPreparedStatement s = p.parsePreparedStatement(sql);
                System.out.println(name + ": " + sql + " -> hasErrors=" + s.isHasErrors() + ", table=" + s.getTable());
            }
        }
    }
}

Configuration

Client Configuration

// jdbc_sql_parser=ANTLR4 or ANTLR4_PARAMS_PARSER for the parse errors (default: JAVACC)

Environment

  • Cloud
  • Client version: main f01962a (0.12.0-rc1-SNAPSHOT)
  • Language version: OpenJDK 17.0.21.1
  • OS: Linux

ClickHouse Server

  • ClickHouse Server version: 26.11.2.4 (26.10.4.207 does not have the two keywords)
  • ClickHouse Server non-default settings, if any: none
  • CREATE TABLE statements for tables involved: none
  • Sample data for all these tables: none

Classification: impact: none · area: Queries (SQL parser keywords)


Found by automated analysis (Polyglot AI) while working on #3427. Verified against a live server.

Activity

  1. added
    jdbc
    sql-parser
    on Nov 25, 2026
  2. added
    queries
    on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugjdbcqueriessql-parser

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions