in jdbc/src/main/java/software/amazon/timestream/jdbc/TimestreamDataType.java [166:231]
static Type createTypeWithMap(
final Type type,
final Type originalType,
final Map<String, Class<?>> conversionMap) throws SQLException {
// This method recursively construct a new Type object from the original Type using the given conversion map.
//
// The method looks up the original type in the conversion map, and if there a conversion
// exists and the conversion is supported by the driver, the method will construct the new
// Type object as the target type.
//
// For instance, if the original type is a TimeSeries and it is to be converted to an Array.
// The method will use `type.withArrayColumnInfo` containing column information from the
// TimeSeries object.
final String originalScalarType = originalType.getScalarType();
if (originalScalarType != null) {
final TimestreamDataType targetType = retrieveTargetType(
TimestreamDataType.valueOf(originalScalarType),
conversionMap);
return type.withScalarType(targetType.name());
}
final List<ColumnInfo> originalRow = originalType.getRowColumnInfo();
if (originalRow != null) {
final TimestreamDataType targetType = retrieveTargetType(TimestreamDataType.ROW,
conversionMap);
switch (targetType) {
case VARCHAR: {
return type.withScalarType(targetType.name());
}
case TIMESERIES: {
throw Error.createSQLException(
LOGGER,
Error.UNSUPPORTED_CONVERSION,
TimestreamDataType.ROW.name(),
targetType);
}
default: {
final List<ColumnInfo> targetRow = new ArrayList<>();
for (final ColumnInfo columnInfo : originalRow) {
targetRow.add(new ColumnInfo().withType(createTypeWithMap(
new Type(),
columnInfo.getType(),
conversionMap)));
}
return type.withRowColumnInfo(targetRow);
}
}
}
final ColumnInfo originalTimeSeries = originalType.getTimeSeriesMeasureValueColumnInfo();
if (originalTimeSeries != null) {
return createType(type, originalTimeSeries, TimestreamDataType.TIMESERIES, conversionMap);
}
final ColumnInfo originalArray = originalType.getArrayColumnInfo();
if (originalArray != null) {
return createType(type, originalArray, TimestreamDataType.ARRAY, conversionMap);
}
throw new RuntimeException(Error.getErrorMessage(LOGGER, Error.INVALID_TYPE, type));
}