in java/clickhouse-connector/src/main/java/com/epam/deltix/timebase/connector/clickhouse/algos/SchemaProcessor.java [347:413]
public static SqlDataType convertTimebaseDataTypeToClickhouseDataType(DataType tbDataType) {
SqlDataType essentialDataType;
if (tbDataType instanceof com.epam.deltix.qsrv.hf.pub.md.ArrayDataType) {
essentialDataType = new ArraySqlType(
convertTimebaseDataTypeToClickhouseDataType(((com.epam.deltix.qsrv.hf.pub.md.ArrayDataType) tbDataType).getElementDataType()));
} else if (tbDataType instanceof BinaryDataType) {
essentialDataType = new StringDataType();
// @PH: can't use FixedStringDataType, because can't provide MaxSize for BinaryDataType.
// Introspector don't parse 'maximum' paramater of SchemaType annotation for BinaryDataType.
/* BinaryDataType binaryDataType = (BinaryDataType) tbDataType;
essentialDataType = new FixedStringDataType(binaryDataType.getMaxSize());*/
} else if (tbDataType instanceof BooleanDataType) {
essentialDataType = new UInt8DataType();
} else if (tbDataType instanceof CharDataType) {
essentialDataType = new StringDataType();
// @PH: in this case, write data to CH as bytes
//essentialDataType = new FixedStringDataType(2);
} else if (tbDataType instanceof ClassDataType) {
essentialDataType = new NothingDataType();
} else if (tbDataType instanceof DateTimeDataType) {
essentialDataType = new DateTime64DataType();
} else if (tbDataType instanceof EnumDataType) {
List<Enum16DataType.Enum16Value> enumValues = Arrays.stream(((EnumDataType) tbDataType).descriptor.getValues())
.map(item -> new Enum16DataType.Enum16Value(item.symbol, (short) item.value))
.collect(Collectors.toList());
essentialDataType = new Enum16DataType(enumValues);
} else if (tbDataType instanceof FloatDataType) {
FloatDataType tbFloatDataType = (FloatDataType) tbDataType;
if (tbFloatDataType.getScale() == FloatDataType.FIXED_FLOAT) // or encoding?
essentialDataType = new Float32DataType();
else if (tbFloatDataType.getScale() == FloatDataType.FIXED_DOUBLE ||
tbFloatDataType.getScale() == FloatDataType.SCALE_AUTO)
essentialDataType = new Float64DataType();
else if (tbFloatDataType.getScale() == FloatDataType.SCALE_DECIMAL64)
essentialDataType = new DecimalDataType(DEFAULT_DECIMAL_PRECISION, DEFAULT_DECIMAL_SCALE);
else
essentialDataType = new Float64DataType();
// throw new UnsupportedOperationException(String.format("Unexpected scale %d for FloatDataType", tbFloatDataType.getScale()));
} else if (tbDataType instanceof IntegerDataType) {
IntegerDataType tbIntegerDataType = (IntegerDataType) tbDataType;
switch (tbIntegerDataType.getNativeTypeSize()) {
case 1:
essentialDataType = new Int8DataType();
break;
case 2:
essentialDataType = new Int16DataType();
break;
case 4:
essentialDataType = new Int32DataType();
break;
default:
essentialDataType = new Int64DataType();
}
} else if (tbDataType instanceof TimeOfDayDataType) {
essentialDataType = new Int32DataType();
} else if (tbDataType instanceof VarcharDataType) {
essentialDataType = new StringDataType();
} else {
throw new UnsupportedOperationException(String.format("Cannot convert data type '%s'", tbDataType.getClass().getName()));
}
return tbDataType.isNullable() && !(tbDataType instanceof com.epam.deltix.qsrv.hf.pub.md.ArrayDataType) ?
new NullableDataType(essentialDataType) : essentialDataType;
}