Repository navigation
Description
Description
Reading a column of type Array(Point) or Array(Array(Point)) with client-v2 throws IllegalArgumentException: array element type mismatch, and the whole row is lost. This happens in Client#queryAll, in Client#newBinaryFormatReader with RowBinaryWithNamesAndTypes and Native, and in jdbc-v2, where ResultSet#next() throws SQLException. An Array(Point) inside another value fails the same way, for example Map(String, Array(Point)), Tuple(Array(Point), Int32), Variant(Array(Point), String) or a Dynamic that holds an Array(Point). ClickHouse 26.10 and 25.8 give the same result.
Array(Nullable(Point)), an empty Array(Point), Array(Ring) and the other arrays of geo types, Array(Tuple(Point, Int32)), Array(Map(String, Point)), Map(String, Point) and Array(FixedString(3)) are not affected.
BinaryStreamReader.readArrayToArrayValue takes the component class of a non-nullable array from its first element. A Point is read as a double[], so the class is double[]. The ArrayValue constructor then allocates Array.newInstance(Object[].class, length) for every array class. That is an Object[][], and a double[] is not an Object[], so storing the first point fails. A Ring is a double[][], which is an Object[], so Array(Ring) works. Array(Nullable(Point)) uses an Object[] and works.
Array(QBit(Float64, 2)) fails the same way when the client has a type hint that maps Array to an array class, for example Object[].class, because each QBit is then a double[].
This is not the cause of #3192. In #3192 the first IPv6 element sets the component class to Inet4Address or Inet6Address, and a later element of the other class does not fit. Here the component class double[] is right, but the container that ArrayValue allocates for it cannot hold it.
Steps to reproduce
- Connect with client-v2 to ClickHouse 26.10.
- Run
SELECT [(1.5, 2.5), (3.5, 4.5)]::Array(Point) AS p, toInt64(7) AS tailwithClient#queryAllor read it withClient#newBinaryFormatReader. - The read throws the exception below. With jdbc-v2,
ResultSet#next()throws.
Error Log or Exception StackTrace
com.clickhouse.client.api.ClientException: Failed to get query response
at com.clickhouse.client.api.Client.queryAll(Client.java:2252)
at com.clickhouse.client.api.Client.queryAll(Client.java:2265)
at Repro.lambda$main$0(Repro.java:24)
at Repro.run(Repro.java:76)
at Repro.main(Repro.java:23)
Caused by: com.clickhouse.client.api.ClientException: Failed to read value for column p
at com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.readValue(BinaryStreamReader.java:307)
at com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.readValue(BinaryStreamReader.java:135)
at com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.readValue(BinaryStreamReader.java:117)
at com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.readValue(BinaryStreamReader.java:101)
at com.clickhouse.client.api.data_formats.internal.AbstractBinaryFormatReader.readRecord(AbstractBinaryFormatReader.java:168)
at com.clickhouse.client.api.Client.queryAll(Client.java:2244)
... 4 more
Caused by: java.lang.IllegalArgumentException: Failed to set value at index: 0 value [D@7193666c of class [D when array type is class [[Ljava.lang.Object;
at com.clickhouse.client.api.data_formats.internal.BinaryStreamReader$ArrayValue.set(BinaryStreamReader.java:894)
at com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.readArrayToArrayValue(BinaryStreamReader.java:835)
at com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.readArray(BinaryStreamReader.java:788)
at com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.readArray(BinaryStreamReader.java:778)
at com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.readValue(BinaryStreamReader.java:282)
... 9 more
Caused by: java.lang.IllegalArgumentException: array element type mismatch
at java.base/java.lang.reflect.Array.set(Native Method)
at com.clickhouse.client.api.data_formats.internal.BinaryStreamReader$ArrayValue.set(BinaryStreamReader.java:891)
... 13 more
jdbc-v2 gives the same chain from ResultSet#next().
java.sql.SQLException: Failed to read value for column p
at com.clickhouse.jdbc.internal.ExceptionUtils.toSqlState(ExceptionUtils.java:70)
at com.clickhouse.jdbc.internal.ExceptionUtils.toSqlState(ExceptionUtils.java:41)
at com.clickhouse.jdbc.ResultSetImpl.next(ResultSetImpl.java:160)
...
Caused by: com.clickhouse.client.api.ClientException: Failed to read value for column p
at com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.readValue(BinaryStreamReader.java:307)
...
at com.clickhouse.client.api.data_formats.internal.AbstractBinaryFormatReader.next(AbstractBinaryFormatReader.java:281)
at com.clickhouse.jdbc.ResultSetImpl.next(ResultSetImpl.java:149)
... 3 more
Caused by: java.lang.IllegalArgumentException: Failed to set value at index: 0 value [D@6f4a47c7 of class [D when array type is class [[Ljava.lang.Object;
Caused by: java.lang.IllegalArgumentException: array element type mismatch
Expected Behaviour
The row reads. getList("p") returns one double[] for each point, the class that a Point column returns. getObjectArray("p") returns an Object[] of the same double[] values, as it does for Array(Nullable(Point)). getLong("tail") returns 7. In jdbc-v2, ResultSet#next() succeeds. getArray and getObject of the column also need the fix for #3378.
Code Example
Client client = new Client.Builder()
.addEndpoint("http://127.0.0.1:8123")
.setUsername("default").setPassword("")
.build();
// throws ClientException caused by IllegalArgumentException: array element type mismatch
client.queryAll("SELECT [(1.5, 2.5), (3.5, 4.5)]::Array(Point) AS p, toInt64(7) AS tail");
client.queryAll("SELECT [[(1.5, 2.5)], []]::Array(Array(Point)) AS p, toInt64(7) AS tail");
// jdbc-v2, rs.next() throws SQLException
try (Connection conn = DriverManager.getConnection("jdbc:clickhouse://127.0.0.1:8123/default", "default", "");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT [(1.5, 2.5), (3.5, 4.5)]::Array(Point) AS p")) {
rs.next();
}Configuration
Client Configuration
// defaults, only endpoint and credentials setEnvironment
- Cloud
- Client version: client-v2 and jdbc-v2 0.12.0-rc1-SNAPSHOT, main at 7506301
- Language version: Java 21
- OS: macOS
ClickHouse Server
- ClickHouse Server version: 26.10.4.207, also 25.8.33.6
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved: none, the query reads a literal- Sample data for all these tables, use clickhouse-obfuscator if necessary: none
Activity