-
Couldn't load subscription status.
- Fork 613
Open
Labels
Milestone
Description
Description
With client-v2, reading a column of type Array(Variant(...)) produces an exception if the array contains values of varying types.
Steps to reproduce
CREATE TABLE test
(
key String,
val Array(Variant(Bool,String))
)
ENGINE = MergeTree
ORDER BY (key);
INSERT INTO test VALUES ('a', [true, true]);
INSERT INTO test VALUES ('b', [true, 'z']);Client client = new Client.Builder()
.addEndpoint("http://localhost:8123/")
.setUsername("user")
.setPassword("pass")
.build();
TableSchema schema = new TableSchema(List.of(ClickHouseColumn.of("val", "Array(Variant(Bool,String))")));
QuerySettings settings = new QuerySettings().setFormat(ClickHouseFormat.RowBinary);
// Array contains all of same type - this succeeds.
QueryResponse response1 = client.query("select val from test where key='a'", settings).get();
ClickHouseBinaryFormatReader reader1 = client.newBinaryFormatReader(response1, schema);
reader1.next();
List<Object> val = reader1.getList(1);
// Array contains varying types - this fails.
QueryResponse response2 = client.query("select val from test where key='b'", settings).get();
ClickHouseBinaryFormatReader reader2 = client.newBinaryFormatReader(response2, schema);
reader2.next();Error Log or Exception StackTrace
Exception in thread "main" com.clickhouse.client.api.ClientException: Failed to read value for column val
at com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.readValue(BinaryStreamReader.java:259)
at com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.readValue(BinaryStreamReader.java:90)
at com.clickhouse.client.api.data_formats.internal.AbstractBinaryFormatReader.readRecord(AbstractBinaryFormatReader.java:179)
at com.clickhouse.client.api.data_formats.internal.AbstractBinaryFormatReader.readNextRecord(AbstractBinaryFormatReader.java:224)
at com.clickhouse.client.api.data_formats.RowBinaryFormatReader.<init>(RowBinaryFormatReader.java:23)
at com.clickhouse.client.api.Client.newBinaryFormatReader(Client.java:1982)
at com.example.Test.main(Test.java:28)
Caused by: java.lang.IllegalArgumentException: Failed to set value at index: 1 value b of class java.lang.String
at com.clickhouse.client.api.data_formats.internal.BinaryStreamReader$ArrayValue.set(BinaryStreamReader.java:699)
at com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.readArrayItem(BinaryStreamReader.java:651)
at com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.readArray(BinaryStreamReader.java:612)
at com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.readValue(BinaryStreamReader.java:235)
... 6 more
Caused by: java.lang.IllegalArgumentException: argument 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:696)
... 9 more
Expected Behaviour
Read and return the column value as List<Object>.
Configuration
Environment
- Client version: 0.9.2
- Language version: Java 21
ClickHouse Server
- ClickHouse Server version: 25.6.8.10
- ClickHouse Server non-default settings, if any: