use of io.trino.plugin.jdbc.BooleanReadFunction in project trino by trinodb.
the class PostgreSqlClient method arrayReadFunction.
private static ObjectReadFunction arrayReadFunction(Type elementType, ReadFunction elementReadFunction) {
return ObjectReadFunction.of(Block.class, (resultSet, columnIndex) -> {
Array array = resultSet.getArray(columnIndex);
BlockBuilder builder = elementType.createBlockBuilder(null, 10);
try (ResultSet arrayAsResultSet = array.getResultSet()) {
while (arrayAsResultSet.next()) {
if (elementReadFunction.isNull(arrayAsResultSet, ARRAY_RESULT_SET_VALUE_COLUMN)) {
builder.appendNull();
} else if (elementType.getJavaType() == boolean.class) {
elementType.writeBoolean(builder, ((BooleanReadFunction) elementReadFunction).readBoolean(arrayAsResultSet, ARRAY_RESULT_SET_VALUE_COLUMN));
} else if (elementType.getJavaType() == long.class) {
elementType.writeLong(builder, ((LongReadFunction) elementReadFunction).readLong(arrayAsResultSet, ARRAY_RESULT_SET_VALUE_COLUMN));
} else if (elementType.getJavaType() == double.class) {
elementType.writeDouble(builder, ((DoubleReadFunction) elementReadFunction).readDouble(arrayAsResultSet, ARRAY_RESULT_SET_VALUE_COLUMN));
} else if (elementType.getJavaType() == Slice.class) {
elementType.writeSlice(builder, ((SliceReadFunction) elementReadFunction).readSlice(arrayAsResultSet, ARRAY_RESULT_SET_VALUE_COLUMN));
} else {
elementType.writeObject(builder, ((ObjectReadFunction) elementReadFunction).readObject(arrayAsResultSet, ARRAY_RESULT_SET_VALUE_COLUMN));
}
}
}
return builder.build();
});
}
Aggregations