Search in sources :

Example 1 with DoubleReadFunction

use of io.trino.plugin.jdbc.DoubleReadFunction 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();
    });
}
Also used : Array(java.sql.Array) TypeUtils.getJdbcObjectArray(io.trino.plugin.postgresql.TypeUtils.getJdbcObjectArray) DoubleReadFunction(io.trino.plugin.jdbc.DoubleReadFunction) BooleanReadFunction(io.trino.plugin.jdbc.BooleanReadFunction) ResultSet(java.sql.ResultSet) BlockBuilder(io.trino.spi.block.BlockBuilder)

Aggregations

BooleanReadFunction (io.trino.plugin.jdbc.BooleanReadFunction)1 DoubleReadFunction (io.trino.plugin.jdbc.DoubleReadFunction)1 TypeUtils.getJdbcObjectArray (io.trino.plugin.postgresql.TypeUtils.getJdbcObjectArray)1 BlockBuilder (io.trino.spi.block.BlockBuilder)1 Array (java.sql.Array)1 ResultSet (java.sql.ResultSet)1