in jdbc/src/main/java/software/amazon/timestream/jdbc/TimestreamStruct.java [125:227]
private List<Object> parseRow(
final List<Datum> row,
final List<TimestreamDataType> baseTypeList,
final Map<String, Class<?>> map) throws SQLException {
final List<Object> rowList = new ArrayList<>();
final List<JdbcType> targetTypeList = new ArrayList<>();
for (TimestreamDataType timestreamDataType : baseTypeList) {
final Class<?> targetClass = map.get(timestreamDataType.name());
final JdbcType targetType =
targetClass != null
? TimestreamDataType.convertClassNameToJdbcType(targetClass.getName())
: timestreamDataType.getJdbcType();
targetTypeList.add(targetType);
}
int i = 0;
for (final Datum datum : row) {
final TimestreamDataType baseType;
final JdbcType targetType;
if (baseTypeList.size() == 1) {
baseType = baseTypeList.get(0);
targetType = targetTypeList.get(0);
} else {
baseType = baseTypeList.get(i);
targetType = targetTypeList.get(i);
}
switch (baseType) {
case ARRAY: {
final TimestreamArray timestreamArray = new TimestreamArray(
(List<Object>) (Object) datum.getArrayValue(),
this.typeList.get(i).getArrayColumnInfo().getType(),
this.parentResultSet,
map);
if (targetType == JdbcType.VARCHAR) {
rowList.add(String.valueOf(timestreamArray.getArrayList()));
continue;
}
final List<Object> resultList = TimestreamArray.populateArrayListToDatum(
timestreamArray.getArrayList(), timestreamArray);
final TimestreamArray convertedArray = new TimestreamArray(
resultList,
this.typeList.get(i).getArrayColumnInfo().getType(),
this.parentResultSet,
map);
rowList.add(convertedArray);
break;
}
case ROW: {
final TimestreamStruct timestreamStruct = new TimestreamStruct(
datum.getRowValue().getData(),
this.typeList.get(i).getRowColumnInfo(),
this.parentResultSet,
map);
if (targetType == JdbcType.VARCHAR) {
final List<Datum> data = new ArrayList<>();
for (final Object attribute : timestreamStruct.getAttributes()) {
data.add(new Datum().withScalarValue(attribute.toString()));
}
final Object convertedResult = Conversions.convert(
baseType,
targetType,
new Datum().withRowValue(new Row().withData(data)),
this.parentResultSet::addWarning
);
rowList.add(convertedResult);
continue;
}
final List<Datum> convertedDatumList =
populateObjectToDatum(timestreamStruct.getAttributes());
final TimestreamStruct convertedStruct = new TimestreamStruct(
convertedDatumList,
this.typeList.get(i).getRowColumnInfo(),
this.parentResultSet,
map);
rowList.add(convertedStruct);
break;
}
default: {
rowList.add(Conversions.convert(
baseType,
targetType,
datum,
this.parentResultSet::addWarning
));
break;
}
}
i++;
}
return rowList;
}