Skip to content

Commit

Permalink
added tuple support
Browse files Browse the repository at this point in the history
  • Loading branch information
chernser committed Sep 25, 2024
1 parent b8f3b41 commit 0de9eb2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,18 @@ private static void serializeArrayData(OutputStream stream, Object value, ClickH
private static void serializeTupleData(OutputStream stream, Object value, ClickHouseColumn column) throws IOException {
//Serialize the tuple to the stream
//The tuple is a list of values
List<?> values = (List<?>) value;
for (int i = 0; i < values.size(); i++) {
serializeData(stream, values.get(i), column.getNestedColumns().get(i));
if (value instanceof List) {
List<?> values = (List<?>) value;
for (int i = 0; i < values.size(); i++) {
serializeData(stream, values.get(i), column.getNestedColumns().get(i));
}
} else if (value instanceof Object[]) {
Object[] values = (Object[]) value;
for (int i = 0; i < values.length; i++) {
serializeData(stream, values[i], column.getNestedColumns().get(i));
}
} else {
throw new IllegalArgumentException("Cannot serialize " + value + " as a tuple");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public class QuerySamplePOJO {

private List<String> array;
private List<?> tuple;

private Object[] tupleArray;

private Map<String, Integer> map;
private List<Integer> nestedInnerInt;
private List<String> nestedInnerString;
Expand Down Expand Up @@ -143,6 +146,7 @@ public QuerySamplePOJO() {

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");
tuple = Arrays.asList(random.nextInt(), random.nextDouble(), "a", "b");
tupleArray = new Object[] {random.nextInt(), random.nextDouble(), "c", "d" };
map = new HashMap<>();
for (int i = 0; i < 10; i++) {
map.put(String.valueOf((char) ('a' + i)), i + 1);
Expand Down Expand Up @@ -437,6 +441,14 @@ public void setTuple(List<?> tuple) {
this.tuple = tuple;
}

public Object[] getTupleArray() {
return tupleArray;
}

public void setTupleArray(Object[] tupleArray) {
this.tupleArray = tupleArray;
}

public Map<String, Integer> getMap() {
return map;
}
Expand Down Expand Up @@ -560,6 +572,7 @@ public static String generateTableCreateSQL(String tableName) {
"ipv6 IPv6, " +
"array Array(String), " +
"tuple Tuple(Int32, Float64, String, String), " +
"tupleArray Tuple(Int32, Float64, String, String), " +
"map Map(String, Int32), " +
"nested Nested (innerInt Int32, innerString String)" +
") ENGINE = Memory";
Expand Down

0 comments on commit 0de9eb2

Please sign in to comment.