Skip to content

Commit

Permalink
Merge pull request #1889 from Am-phi/clientv2_illegalArgumentExceptio…
Browse files Browse the repository at this point in the history
…n_for_tuple_in_array

[Client v2] illegal argument exception for tuple in array
  • Loading branch information
chernser authored Oct 28, 2024
2 parents 077dfa8 + 09177c8 commit 54cb400
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ public static class ArrayValue {
try {
if (itemType.isArray()) {
array = Array.newInstance(ArrayValue.class, length);
} else if (itemType == List.class) {
array = Array.newInstance(Object[].class, length);
} else {
array = Array.newInstance(itemType, length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.clickhouse.client.api.DataTypeUtils;
import com.clickhouse.client.api.ServerException;
import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader;
import com.clickhouse.client.api.data_formats.internal.BinaryStreamReader;
import com.clickhouse.client.api.enums.Protocol;
import com.clickhouse.client.api.insert.InsertSettings;
import com.clickhouse.client.api.metadata.TableSchema;
Expand Down Expand Up @@ -49,6 +50,7 @@
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.nio.file.Files;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
Expand All @@ -64,6 +66,7 @@
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -982,6 +985,40 @@ public void testDecimalDataTypes() {
testDataTypes(columns, valueGenerators, verifiers);
}


@Test(groups = {"integration"})
public void testArrayTuples() {
final List<String> columns = Arrays.asList(
"col1 Array(Tuple(UInt32, String))",
"col2 Array(Tuple(UInt32, String, Float32))",
"col3 Array(Tuple(UInt32, Tuple(Float32, String)))"
);

final List<Supplier<String>> valueGenerators = Arrays.asList(
() -> "[(1, 'value1'), (2, 'value2')]",
() -> "[(1, 'value2', 23.43), (2, 'value3', 43.21)]",
() -> "[(1, (23.43, 'value3')), (2, (43.21, 'value4'))]"
);

final List<Consumer<ClickHouseBinaryFormatReader>> verifiers = new ArrayList<>();
verifiers.add(r -> {
Assert.assertTrue(r.hasValue("col1"), "No value for column col1 found");
Assert.assertEquals(r.getList("col1").get(0), new Object[]{1L, "value1"});
Assert.assertEquals(r.getList("col1").get(1), new Object[]{2L, "value2"});
});
verifiers.add(r -> {
Assert.assertTrue(r.hasValue("col2"), "No value for column col2 found");
Assert.assertEquals(r.getList("col2").get(0), new Object[]{1L, "value2", 23.43f});
Assert.assertEquals(r.getList("col2").get(1), new Object[]{2L, "value3", 43.21f});
});
verifiers.add(r -> {
Assert.assertTrue(r.hasValue("col3"), "No value for column col2 found");
Assert.assertEquals(r.getList("col3").get(0), new Object[]{1L, new Object[]{23.43f, "value3"}});
Assert.assertEquals(r.getList("col3").get(1), new Object[]{2L, new Object[]{43.21f, "value4"}});
});

testDataTypes(columns, valueGenerators, verifiers);
}
@Test(groups = {"integration"})
public void testTuples() {
final List<String> columns = Arrays.asList(
Expand Down

0 comments on commit 54cb400

Please sign in to comment.