clickhouse-java icon indicating copy to clipboard operation
clickhouse-java copied to clipboard

Passing a `List<String>` as a query parameter in client-v2 requires to single quote every element

Open jnd77 opened this issue 6 months ago • 1 comments

Description

The API for query parameters could be more user-friendly for List<String>, and not require to manually surround every string element with a single quote.

Steps to reproduce

See test below.

Error Log or Exception StackTrace

Code: 26. DB::Exception: Cannot parse quoted string: expected opening quote ''', got 'C': value [COLLATIONS, ENGINES] cannot be parsed as Array(String) for query parameter 'table_names'. (CANNOT_PARSE_QUOTED_STRING) (version 25.3.3.42 (official build))

Expected Behaviour

Code Example

  @Test
  void testParamsWithStringList() 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_names", List.of("COLLATIONS", "ENGINES"));
    // This query should not throw an exception
    client.query("SELECT database, name FROM system.tables WHERE name in {table_names:Array(String)}", params).get();
  }

Test is passing when using Map.of("table_names", List.of("'COLLATIONS'", "'ENGINES'")) as params.

Configuration

Client Configuration

See above.

Environment

  • [ ] Cloud
  • Client version: 0.8.6
  • Language version:
  • OS:

ClickHouse Server

  • ClickHouse Server version: 25.3.3.42
  • ClickHouse Server non-default settings, if any:
  • CREATE TABLE statements for tables involved:
  • Sample data for all these tables, use clickhouse-obfuscator if necessary

jnd77 avatar Jun 03 '25 07:06 jnd77

@jnd77 thank you for reporting! We will look into it.

chernser avatar Jun 05 '25 01:06 chernser