Skip to content

Query parameters can not be parsed in DESCRIBE TABLE query with client-v2 #2400

Open

Description

@jnd77

Description

Bug with Client#query(sql, params) for a DESCRIBE TABLE query.

Steps to reproduce

See the unit test below.
The parameter name is not substituted.

Error Log or Exception StackTrace

com.clickhouse.client.api.ServerException: Code: 62. DB::Exception: Syntax error: failed at position 33 (}): }. Expected substitution type (identifier). (SYNTAX_ERROR)

Expected Behaviour

Code Example

  @Test
  void testWeirdBugWithParams() throws Exception {
    final Client client = new Client.Builder()
        .addEndpoint(Protocol.HTTP, "localhost", 8123, false)
        .setUsername("default")
        .setPassword("")
        .build();
    final Map<String, Object> params = Map.of("table_name", "`system`.`tables`");
    // This query should not throw an exception
    client.query("DESCRIBE TABLE {table_name:String}", params).get();
  }

Configuration

Client Configuration

See above.

Environment

  • Cloud
  • Client version: 0.8.6
  • Language version: Java 17
  • OS: Linux

ClickHouse Server

  • ClickHouse Server version: 25.3.3.42 (official build)

Activity

  1. changed the title [-]Query parameters are ignored in ` "DESCRIBE TABLE" query with client-v2[/-] [+]Query parameters are ignored in `DESCRIBE TABLE` query with client-v2[/+] on Jun 2, 2025
  2. added
    client
    on Jun 2, 2025
  3. changed the title [-]Query parameters are ignored in `DESCRIBE TABLE` query with client-v2[/-] [+]Query parameters can not be parsed in `DESCRIBE TABLE` query with client-v2[/+] on Jun 3, 2025
  4. added this to the 0.9.10 milestone on Apr 15, 2026
  5. chernser commented on Jul 9, 2026

    @chernser
    Contributor

    /triage

  6. github-actions commented on Jul 9, 2026

    @github-actions

    Triage Report

    Effort to Fix: Small
    Type: Bug
    Affected Module: client-v2 (client-api-v2)

    Summary

    When calling Client#query("DESCRIBE TABLE {table_name:String}", params), the server rejects the query with a syntax error at position 33 (the closing } of the substitution). The client correctly passes param_table_name as a URL query parameter, but ClickHouse cannot apply {name:String} substitution in a DESCRIBE TABLE table-name position because String-typed parameters are resolved as quoted string literals — making the resulting SQL (DESCRIBE TABLE 'system.tables') syntactically invalid. The correct ClickHouse type for substituting an identifier (table/column name) is Identifier, not String. It is not yet confirmed whether this is a pure user-education issue or whether the client should detect and surface a clearer error.

    Recommended Labels & Priority

    • Labels: bug, client-api-v2, area:client-read

    Missing Information / Questions for User

    1. Does changing the query to DESCRIBE TABLE {table_name:Identifier} (type Identifier instead of String) resolve the error?
    2. Can you share the raw HTTP request (enable debug logging with -Dorg.slf4j.simpleLogger.defaultLogLevel=DEBUG) to confirm param_table_name is included in the URL?
    3. Is the issue reproducible with other ClickHouse server versions (e.g., 24.x)?

    Tests to Add

    Test 1: DESCRIBE TABLE with Identifier-typed query parameter

    @Test(groups = {"integration"})
    public void testQueryParamsInDescribeTable() throws Exception {
        // {name:Identifier} is the correct ClickHouse type for a table-name substitution
        final Map<String, Object> params = Map.of("table_name", "system.tables");
        try (QueryResponse response =
                 client.query("DESCRIBE TABLE {table_name:Identifier}", params).get()) {
            Assert.assertNotNull(response);
        }
    }

    Test 2: DESCRIBE TABLE with String-typed parameter should fail with a clear error

    @Test(groups = {"integration"})
    public void testQueryParamsInDescribeTableStringTypeFails() {
        // String type resolves to a quoted literal, which is invalid in the table-name position;
        // verify the client surfaces a ServerException rather than an opaque failure.
        final Map<String, Object> params = Map.of("table_name", "system.tables");
        try {
            client.query("DESCRIBE TABLE {table_name:String}", params).get();
            Assert.fail("Expected ServerException");
        } catch (ExecutionException e) {
            Assert.assertTrue(e.getCause() instanceof ServerException,
                "Expected ServerException, got: " + e.getCause());
        }
    }
  7. kishansinghifs1 commented on Jul 22, 2026

    @kishansinghifs1
    Contributor

    Hii @chernser I would like to work on it.

  8. chernser commented on Jul 22, 2026

    @chernser
    Contributor

    @kishansinghifs1
    What would be the fix?
    please describe briefly.

    Thanks!

  9. modified the milestones: 0.11.0, 0.12.0 on Sep 23, 2026
  10. kishansinghifs1 commented on Sep 26, 2026

    @kishansinghifs1
    Contributor

    Hiii @chernser, so sorry! I was going through some health issues and wasn’t really able to get back to you. Apologies for the delayed response.

  11. kishansinghifs1 commented on Sep 26, 2026

    @kishansinghifs1
    Contributor

    Here is the doc containing the implementation proposal along with the queries that need to be answered:

    Issue:#2827

  12. chernser commented on Sep 27, 2026

    @chernser
    Contributor

    @kishansinghifs1
    no worries!

    Thank you for the document - I will read next week.

  13. removed this from the 0.12.0 milestone on Nov 11, 2026
  14. added
    queries
    and removed on Nov 26, 2026
  15. polyglotAI-bot commented on Nov 28, 2026

    @polyglotAI-bot
    Collaborator

    Recommendation: Close — no-op: works as intended
    The server accepts only the type Identifier for a parameter in a table-name position, and the client sends the query and the parameter unchanged. Correct usage: DESCRIBE TABLE {db:Identifier}.{table:Identifier} with db=system and table=tables.

    Analysis: In a table-name position, the server parser accepts only a {name:Identifier} substitution, so {table_name:String} fails with Expected substitution type (identifier) before the server uses the value. One Identifier value is one name: the server reads `system`.`tables` as one table name, so the database and the table need a parameter each.

    Reproduction: complete program and output

    Changed from the issue's steps: the test body is in main, and two cases with Identifier parameters are added.

    import com.clickhouse.client.api.Client;
    import com.clickhouse.client.api.query.QueryResponse;
    import java.util.HashMap;
    import java.util.Map;
    
    public class Repro {
        static final String URL = System.getenv().getOrDefault("CLICKHOUSE_URL", "http://localhost:8123");
        static final String PASSWORD = System.getenv().getOrDefault("CLICKHOUSE_PASSWORD", "");
    
        static void run(Client client, String sql, Map<String, Object> params) {
            try (QueryResponse r = client.query(sql, params).get()) {
                System.out.println(sql + " " + params + " -> OK, rows=" + r.getResultRows());
            } catch (Exception e) {
                Throwable c = e.getCause() != null ? e.getCause() : e;
                System.out.println(sql + " " + params + " -> " + c.getClass().getSimpleName() + ": " + c.getMessage());
            }
        }
    
        public static void main(String[] args) throws Exception {
            try (Client client = new Client.Builder().addEndpoint(URL)
                    .setUsername("default").setPassword(PASSWORD).build()) {
                Map<String, Object> p1 = new HashMap<>();
                p1.put("table_name", "`system`.`tables`");
                run(client, "DESCRIBE TABLE {table_name:String}", p1);
                run(client, "DESCRIBE TABLE {table_name:Identifier}", p1);
                Map<String, Object> p2 = new HashMap<>();
                p2.put("db", "system");
                p2.put("table", "tables");
                run(client, "DESCRIBE TABLE {db:Identifier}.{table:Identifier}", p2);
            }
        }
    }

    Output on main (8480ca001), ClickHouse 26.11.4.11:

    DESCRIBE TABLE {table_name:String} {table_name=`system`.`tables`} -> ServerException: Code: 62. DB::Exception: Syntax error: failed at position 34 (}): }. Expected substitution type (identifier). (SYNTAX_ERROR) …
    DESCRIBE TABLE {table_name:Identifier} {table_name=`system`.`tables`} -> ServerException: Code: 60. DB::Exception: Table default.`\`system\`.\`tables\`` does not exist. (UNKNOWN_TABLE) …
    DESCRIBE TABLE {db:Identifier}.{table:Identifier} {db=system, table=tables} -> OK, rows=44
    

    Automated triage by Polyglot AI. A maintainer makes the final decision.

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

    clientqueriesquestion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions