Skip to content

Commit 0de9eb2

Browse files
committed
added tuple support
1 parent b8f3b41 commit 0de9eb2

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,18 @@ private static void serializeArrayData(OutputStream stream, Object value, ClickH
8181
private static void serializeTupleData(OutputStream stream, Object value, ClickHouseColumn column) throws IOException {
8282
//Serialize the tuple to the stream
8383
//The tuple is a list of values
84-
List<?> values = (List<?>) value;
85-
for (int i = 0; i < values.size(); i++) {
86-
serializeData(stream, values.get(i), column.getNestedColumns().get(i));
84+
if (value instanceof List) {
85+
List<?> values = (List<?>) value;
86+
for (int i = 0; i < values.size(); i++) {
87+
serializeData(stream, values.get(i), column.getNestedColumns().get(i));
88+
}
89+
} else if (value instanceof Object[]) {
90+
Object[] values = (Object[]) value;
91+
for (int i = 0; i < values.length; i++) {
92+
serializeData(stream, values[i], column.getNestedColumns().get(i));
93+
}
94+
} else {
95+
throw new IllegalArgumentException("Cannot serialize " + value + " as a tuple");
8796
}
8897
}
8998

client-v2/src/test/java/com/clickhouse/client/query/QuerySamplePOJO.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ public class QuerySamplePOJO {
6868

6969
private List<String> array;
7070
private List<?> tuple;
71+
72+
private Object[] tupleArray;
73+
7174
private Map<String, Integer> map;
7275
private List<Integer> nestedInnerInt;
7376
private List<String> nestedInnerString;
@@ -143,6 +146,7 @@ public QuerySamplePOJO() {
143146

144147
array = Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
145148
tuple = Arrays.asList(random.nextInt(), random.nextDouble(), "a", "b");
149+
tupleArray = new Object[] {random.nextInt(), random.nextDouble(), "c", "d" };
146150
map = new HashMap<>();
147151
for (int i = 0; i < 10; i++) {
148152
map.put(String.valueOf((char) ('a' + i)), i + 1);
@@ -437,6 +441,14 @@ public void setTuple(List<?> tuple) {
437441
this.tuple = tuple;
438442
}
439443

444+
public Object[] getTupleArray() {
445+
return tupleArray;
446+
}
447+
448+
public void setTupleArray(Object[] tupleArray) {
449+
this.tupleArray = tupleArray;
450+
}
451+
440452
public Map<String, Integer> getMap() {
441453
return map;
442454
}
@@ -560,6 +572,7 @@ public static String generateTableCreateSQL(String tableName) {
560572
"ipv6 IPv6, " +
561573
"array Array(String), " +
562574
"tuple Tuple(Int32, Float64, String, String), " +
575+
"tupleArray Tuple(Int32, Float64, String, String), " +
563576
"map Map(String, Int32), " +
564577
"nested Nested (innerInt Int32, innerString String)" +
565578
") ENGINE = Memory";

0 commit comments

Comments
 (0)