Skip to content

jdbc-v2: ANTLR4 lexer does not nest /* */ block comments #3021

Closed

Description

@polyglotAI-bot

Describe the bug

ClickHouse nests /* */ block comments — an inner /* raises the nesting level and only the matching */ ends the comment. The jdbc-v2 JavaCC grammar nests (commentNestingDepth in ClickHouseSqlParser.jj) and ClickHouseUtils.skipMultiLineComment nests, but the ANTLR4 lexer rule does not:

MULTI_LINE_COMMENT  : '/*' .*? '*/'  -> skip;

The non-greedy .*? ends the comment at the FIRST */, so everything after it is lexed as SQL. With the ANTLR4 / ANTLR4_PARAMS_PARSER backends this makes statements that the server accepts look like syntax errors, and it skews ? placeholder detection for the ANTLR4_PARAMS_PARSER backend (a ? inside the nested part of the comment is counted as a bind parameter).

Steps to reproduce

Server (26.5) accepts all of these:

SELECT 1 /* ) /* ) */ ) */, 2          -->  1   2
SELECT /* a /* b */ c */ 1             -->  1
SELECT /* ? /* ? */ ? */ 5             -->  5

With ANTLR4 / ANTLR4_PARAMS_PARSER selected (jdbc_parser driver property):

ParsedPreparedStatement stmt = parser.parsePreparedStatement("SELECT /* a /* b */ c */ ?");
stmt.isHasErrors();  // true  (expected: false)
ParsedPreparedStatement stmt = parser.parsePreparedStatement("SELECT 1 /* ) /* ) */ ) */, ?");
stmt.getArgCount();  // 0  (expected: 1)

The JavaCC backend handles all of these correctly, so the behaviour differs between the parser backends.

Expected behaviour

The ANTLR4 lexer skips a nested block comment as a single comment token, matching the server and the JavaCC backend.

Configuration

  • Client version: main (0.11.0-rc1)
  • Language: Java
  • Server version: 26.5.1
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions