Skip to content

[jdbc-v2] getColumnTypeName returns Nullable(Tuple(...)) without its last closing parenthesis #3382

Open

Description

@Indian-boult

Description

The client names a Nullable(Tuple(...)) column one closing parenthesis short. ClickHouseColumn.of("c", "Nullable(Tuple(Int32, String))").getOriginalTypeName() returns Nullable(Tuple(Int32, String). The same happens inside containers, for example for the element of Array(Nullable(Tuple(Int32, String))), the value of Map(String, Nullable(Tuple(Int32, String))) and the element x of Tuple(x Nullable(Tuple(Int32, String)), y Int8).

These effects were checked on main against ClickHouse 26.10.

  1. jdbc-v2 ResultSetMetaData#getColumnTypeName returns Nullable(Tuple(Int32, String).
  2. jdbc-v2 java.sql.Array#getBaseTypeName of an Array(Nullable(Tuple(Int32, String))) value and the type name of the VALUE column of its getResultSet() are Nullable(Tuple(Int32, String). Connection#createArrayOf and Struct#getSQLTypeName of Connection#createStruct give the same short name.
  3. jdbc-v2 java.sql.Array#getResultSet() of a Nested(a Nullable(Tuple(Int32, String)), b Int8) value throws IllegalArgumentException. The driver builds Tuple(a Nullable(Tuple(Int32, String), b Int8) from the short name and parses it again.
  4. client-v2 Client#getTableSchema and the schema of Client#newBinaryFormatReader return the short name, for the column and for nested fields.

The values are read correctly with client-v2 and jdbc-v2. Inserts through RowBinaryFormatWriter with the schema from getTableSchema and through a registered POJO also work. Nullable(JSON(a Int32)) and Nullable(QBit(Float32, 8)) have the same problem. LowCardinality(Nullable(String)) and Nullable(String) are correct.

ClickHouse 26.10 accepts Nullable(Tuple(...)) and returns Nullable(Tuple(Int32, String)) for toTypeName. ClickHouse 25.8 rejects the type.

The cause is in ClickHouseColumn.readColumn. The Nullable and LowCardinality prefixes increase a counter of open brackets. Only the branch for types without parameters reads the matching closing brackets. The branches for Array, Map, Nested, Tuple, Variant, JSON, QBit and AggregateFunction end the type name at their own closing bracket.

Steps to reproduce

  1. Connect with jdbc-v2 to ClickHouse 26.10.
  2. Run the query from the code example.
  3. Call getColumnTypeName(1) on the metadata and getArray("n").getResultSet() on the first row.

Error Log or Exception StackTrace

getColumnTypeName returns Nullable(Tuple(Int32, String)

java.lang.IllegalArgumentException: Missing ')' for '(' at position 5
	at com.clickhouse.data.ClickHouseUtils.skipBrackets(ClickHouseUtils.java:1113)
	at com.clickhouse.data.ClickHouseColumn.readColumn(ClickHouseColumn.java:555)
	at com.clickhouse.data.ClickHouseColumn.of(ClickHouseColumn.java:782)
	at com.clickhouse.jdbc.types.ArrayResultSet.elementColumn(ArrayResultSet.java:105)
	at com.clickhouse.jdbc.types.ArrayResultSet.<init>(ArrayResultSet.java:78)
	at com.clickhouse.jdbc.types.Array.getResultSet(Array.java:112)

Expected Behaviour

getColumnTypeName, getBaseTypeName, getSQLTypeName and TableSchema return Nullable(Tuple(Int32, String)), the same name as the server. getResultSet() of the Nested value returns its rows.

Code Example

Properties props = new Properties();
props.setProperty("user", "default");
props.setProperty("password", "<password>");
try (Connection conn = DriverManager.getConnection("jdbc:clickhouse://localhost:8123/default", props);
     Statement stmt = conn.createStatement();
     ResultSet rs = stmt.executeQuery("SELECT CAST((1, 'a'), 'Nullable(Tuple(Int32, String))') AS t, "
             + "CAST([((1, 'a'), 2), (NULL, 3)], 'Nested(a Nullable(Tuple(Int32, String)), b Int8)') AS n")) {
    System.out.println(rs.getMetaData().getColumnTypeName(1)); // Nullable(Tuple(Int32, String)
    rs.next();
    rs.getArray("n").getResultSet(); // IllegalArgumentException
}

try (Client client = new Client.Builder().addEndpoint("http://localhost:8123").setUsername("default")
        .setPassword("<password>").build()) {
    client.execute("CREATE TABLE t (v Nullable(Tuple(a Int32, b String))) ORDER BY tuple()").get().close();
    System.out.println(client.getTableSchema("t").getColumnByName("v").getOriginalTypeName());
    // Nullable(Tuple(a Int32, b String)
}

Configuration

Client Configuration

// default jdbc-v2 and client-v2 settings

Environment

  • Cloud
  • Client version: main at 7506301, 0.12.0-rc1-SNAPSHOT
  • Language version: Java 21
  • OS: macOS

ClickHouse Server

  • ClickHouse Server version: 26.10.4.207
  • ClickHouse Server non-default settings, if any: none
  • CREATE TABLE statements for tables involved: CREATE TABLE t (v Nullable(Tuple(a Int32, b String))) ORDER BY tuple()
  • Sample data for all these tables, use clickhouse-obfuscator if necessary: not needed, the queries use CAST

Activity

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions