Repository navigation
Description
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.
- jdbc-v2
ResultSetMetaData#getColumnTypeNamereturnsNullable(Tuple(Int32, String). - jdbc-v2
java.sql.Array#getBaseTypeNameof anArray(Nullable(Tuple(Int32, String)))value and the type name of theVALUEcolumn of itsgetResultSet()areNullable(Tuple(Int32, String).Connection#createArrayOfandStruct#getSQLTypeNameofConnection#createStructgive the same short name. - jdbc-v2
java.sql.Array#getResultSet()of aNested(a Nullable(Tuple(Int32, String)), b Int8)value throwsIllegalArgumentException. The driver buildsTuple(a Nullable(Tuple(Int32, String), b Int8)from the short name and parses it again. - client-v2
Client#getTableSchemaand the schema ofClient#newBinaryFormatReaderreturn 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
- Connect with jdbc-v2 to ClickHouse 26.10.
- Run the query from the code example.
- Call
getColumnTypeName(1)on the metadata andgetArray("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 settingsEnvironment
- 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 TABLEstatements 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