Skip to content

Commit b242955

Browse files
authored
Merge pull request #2687 from ClickHouse/client_fix_variant_array
fix reading Array(Varian(String, Int32)) and similar when array has no common component class
2 parents bbc1af2 + 8d8c8f2 commit b242955

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ public ArrayValue readArray(ClickHouseColumn column) throws IOException {
624624

625625
public ArrayValue readArrayItem(ClickHouseColumn itemTypeColumn, int len) throws IOException {
626626
ArrayValue array;
627-
if (itemTypeColumn.isNullable()) {
627+
if (itemTypeColumn.isNullable() || itemTypeColumn.getDataType() == ClickHouseDataType.Variant) {
628628
array = new ArrayValue(Object.class, len);
629629
for (int i = 0; i < len; i++) {
630630
array.set(i, readValue(itemTypeColumn));

client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypeTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,18 @@ public void testVariantWithArrays() throws Exception {
348348
"[[a, b], [c, d]]",
349349
"[[e, f], [j, h]]",
350350
});
351+
352+
testVariantWith("arrays", new String[]{"field Array(Variant(String, Int32))"},
353+
new Object[]{
354+
new Object[]{1, 2},
355+
new Object[]{"a", 3},
356+
new Object[]{3, "d"}
357+
},
358+
new String[]{
359+
"[1, 2]",
360+
"[a, 3]",
361+
"[3, d]",
362+
});
351363
}
352364

353365
@Test(groups = {"integration"})

0 commit comments

Comments
 (0)