in core/src/main/java/org/apache/calcite/avatica/remote/TypedValue.java [329:372]
private static Object serialToJdbc(ColumnMetaData.Rep type, ColumnMetaData.Rep componentRep,
Object value, Calendar calendar) {
switch (type) {
case BYTE_STRING:
return ByteString.ofBase64((String) value).getBytes();
case JAVA_UTIL_DATE:
return DateTimeUtils.unixTimestampToUtilDate((Long) value, calendar);
case JAVA_SQL_DATE:
return DateTimeUtils.unixDateToSqlDate((Integer) value, calendar);
case JAVA_SQL_TIME:
return DateTimeUtils.unixTimeToSqlTime((Integer) value, calendar);
case JAVA_SQL_TIMESTAMP:
return DateTimeUtils.unixTimestampToSqlTimestamp((Long) value, calendar);
case ARRAY:
if (null == value) {
return null;
}
final List<?> list = (List<?>) value;
final List<Object> copy = new ArrayList<>(list.size());
// Copy the list from the serial representation to a JDBC representation
for (Object o : list) {
if (null == o) {
copy.add(null);
} else if (o instanceof TypedValue) {
// Protobuf can maintain the TypedValue hierarchy to simplify things
copy.add(((TypedValue) o).toJdbc(calendar));
} else {
// We can't get the above recursion with the JSON serialization
copy.add(serialToJdbc(componentRep, null, o, calendar));
}
}
if (componentRep == null && list.size() > 0) {
componentRep = ((TypedValue) list.get(0)).type;
if (componentRep == null) {
throw new RuntimeException("ComponentRep of element must not be null for ARRAYs");
}
}
AvaticaType elementType = new AvaticaType(componentRep.typeId, componentRep.name(),
componentRep);
return new ArrayFactoryImpl(calendar.getTimeZone()).createArray(elementType, copy);
default:
return serialToLocal(type, value);
}
}