Skip to content

Commit b8f3b41

Browse files
committed
added tuple support
1 parent c9a1b2d commit b8f3b41

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.clickhouse.client.api.Client;
44
import com.clickhouse.client.api.ClientException;
55
import com.clickhouse.client.api.data_formats.internal.BinaryStreamReader;
6-
import com.clickhouse.client.api.insert.POJOSerializer;
76
import com.clickhouse.client.api.query.POJOSetter;
87
import com.clickhouse.data.ClickHouseAggregateFunction;
98
import com.clickhouse.data.ClickHouseColumn;
@@ -40,6 +39,7 @@
4039
import static org.objectweb.asm.Opcodes.ALOAD;
4140
import static org.objectweb.asm.Opcodes.CHECKCAST;
4241
import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
42+
import static org.objectweb.asm.Opcodes.INVOKESTATIC;
4343
import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
4444
import static org.objectweb.asm.Opcodes.RETURN;
4545

@@ -347,8 +347,18 @@ public static POJOSetter compilePOJOSetter(Method setterMethod, ClickHouseColumn
347347
Type.getType(ClickHouseColumn.class),
348348
Type.getType(Class.class)),
349349
false);
350-
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(targetType));
351-
// cast to target type
350+
351+
if (targetType.isAssignableFrom(List.class) && column.getDataType() == ClickHouseDataType.Tuple) {
352+
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(Object[].class));
353+
mv.visitMethodInsn(INVOKESTATIC,
354+
Type.getInternalName(Arrays.class),
355+
"asList",
356+
Type.getMethodDescriptor(Type.getType(List.class), Type.getType(Object[].class)),
357+
false);
358+
} else {
359+
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(targetType));
360+
// cast to target type
361+
}
352362
}
353363

354364
// finally call setter with the result of target class

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class QuerySamplePOJO {
6767
private Inet6Address ipv6;
6868

6969
private List<String> array;
70-
// private List<?> tuple;
70+
private List<?> tuple;
7171
private Map<String, Integer> map;
7272
private List<Integer> nestedInnerInt;
7373
private List<String> nestedInnerString;
@@ -142,7 +142,7 @@ public QuerySamplePOJO() {
142142
}
143143

144144
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");
145-
// tuple = Arrays.asList(new Object[]{random.nextInt(), random.nextDouble(), "a", "b" });
145+
tuple = Arrays.asList(random.nextInt(), random.nextDouble(), "a", "b");
146146
map = new HashMap<>();
147147
for (int i = 0; i < 10; i++) {
148148
map.put(String.valueOf((char) ('a' + i)), i + 1);
@@ -429,13 +429,13 @@ public void setArray(List<String> array) {
429429
this.array = array;
430430
}
431431

432-
// public List<?> getTuple() {
433-
// return tuple;
434-
// }
432+
public List<?> getTuple() {
433+
return tuple;
434+
}
435435

436-
// public void setTuple(List<?> tuple) {
437-
// this.tuple = tuple;
438-
// }
436+
public void setTuple(List<?> tuple) {
437+
this.tuple = tuple;
438+
}
439439

440440
public Map<String, Integer> getMap() {
441441
return map;
@@ -559,7 +559,7 @@ public static String generateTableCreateSQL(String tableName) {
559559
"ipv4 IPv4, " +
560560
"ipv6 IPv6, " +
561561
"array Array(String), " +
562-
// "tuple Tuple(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32), " +
562+
"tuple Tuple(Int32, Float64, String, String), " +
563563
"map Map(String, Int32), " +
564564
"nested Nested (innerInt Int32, innerString String)" +
565565
") ENGINE = Memory";

0 commit comments

Comments
 (0)