in jdbc/src/main/java/software/amazon/timestream/jdbc/TimestreamDataType.java [358:405]
static Datum createDatum(final Datum datum, Object value, final Type valueType)
throws SQLException {
if (valueType.getScalarType() != null) {
if (value instanceof Datum) {
return (Datum) value;
}
return datum.withScalarValue(value.toString());
}
if (valueType.getArrayColumnInfo() != null) {
// The value is a TimestreamArray. This happens when we are inside a nested array. We need
// to call `getArrayList` here to retrieve the parsed values in the TimestreamArray.
value = ((TimestreamArray) value).getArrayList();
final List<Datum> arrayValueList = new ArrayList<>();
for (final Object val : (List<Object>) value) {
arrayValueList.add(createDatum(new Datum(), val, valueType.getArrayColumnInfo().getType()));
}
return datum.withArrayValue(arrayValueList);
}
if (valueType.getRowColumnInfo() != null) {
final List<Datum> newRowData = new ArrayList<>();
final List<Datum> rowData = ((TimestreamStruct) value).getStruct();
final List<ColumnInfo> columnInfoList = valueType.getRowColumnInfo();
for (int i = 0; i < rowData.size(); i++) {
final Datum val = rowData.get(i);
newRowData.add(createDatum(new Datum(), val, columnInfoList.get(i).getType()));
}
return datum.withRowValue(new Row().withData(newRowData));
}
if (valueType.getTimeSeriesMeasureValueColumnInfo() != null) {
if (value instanceof TimeSeriesDataPoint) {
// This should not happen, a TimeSeries object is a list of TimeSeriesDataPoint,
// if the value is not within an ArrayList, an error has occurred while converting the data to
// a TimestreamArray. Since calling `new Datum().withTimeSeriesValue((TimeSeriesDataPoint) value)`
// will create a new ArrayList with the value, there is no a breaking error.
LOGGER.warn("The TimeSeries value {} is not wrapped in an array list.", value);
return new Datum().withTimeSeriesValue((TimeSeriesDataPoint) value);
}
return new Datum().withTimeSeriesValue((Collection<TimeSeriesDataPoint>) value);
}
throw new RuntimeException(Error.getErrorMessage(LOGGER, Error.INVALID_TYPE, valueType));
}