#1653 - ENH: Add support for ClickHouse database

With array type conversion for primitive arrays
This commit is contained in:
rob bygrave
2019-03-20 23:13:50 +13:00
parent a3d4b57b94
commit 812dcbb4bb
2 changed files with 47 additions and 1 deletions
@@ -49,4 +49,10 @@ public class ClickHousePlatform extends DatabasePlatform {
dbTypeMap.put(DbType.INET, new DbPlatformType("String", false));
dbTypeMap.put(DbType.CDIR, new DbPlatformType("String", false));
}
@Override
public boolean isNativeArrayType() {
return true;
}
}
@@ -18,13 +18,53 @@ abstract class ScalarTypeArrayBase<T> extends ScalarTypeJsonCollection<T> {
return null;
} else {
try {
return fromArray((Object[]) array.getArray());
return fromArray(convertArray(array.getArray()));
} finally {
array.free();
}
}
}
private Object[] convertArray(Object array) {
if (array instanceof Object[]) {
return (Object[]) array;
}
if (array instanceof long[]) {
return convertLongs((long[]) array);
}
if (array instanceof int[]) {
return convertInts((int[]) array);
}
if (array instanceof double[]) {
return convertDoubles((double[]) array);
}
throw new IllegalArgumentException("Unable to convert array " + array);
}
private Object[] convertLongs(long[] o) {
Long[] list = new Long[o.length];
for (int i = 0; i < o.length; i++) {
list[i] = o[i];
}
return list;
}
private Object[] convertInts(int[] o) {
Integer[] list = new Integer[o.length];
for (int i = 0; i < o.length; i++) {
list[i] = o[i];
}
return list;
}
private Object[] convertDoubles(double[] o) {
Double[] list = new Double[o.length];
for (int i = 0; i < o.length; i++) {
list[i] = o[i];
}
return list;
}
protected abstract T fromArray(Object[] array1);
}