Search in sources :

Example 6 with SingleRowBlockWriter

use of io.trino.spi.block.SingleRowBlockWriter in project trino by trinodb.

the class CassandraType method buildUserTypeValue.

private Block buildUserTypeValue(GettableByIndexData row, int position) {
    verify(this.kind == Kind.UDT, "Not a user defined type: %s", this.kind);
    UDTValue udtValue = row.getUDTValue(position);
    String[] fieldNames = udtValue.getType().getFieldNames().toArray(String[]::new);
    RowBlockBuilder blockBuilder = (RowBlockBuilder) this.trinoType.createBlockBuilder(null, 1);
    SingleRowBlockWriter singleRowBlockWriter = blockBuilder.beginBlockEntry();
    int tuplePosition = 0;
    for (CassandraType argumentType : this.getArgumentTypes()) {
        int finalTuplePosition = tuplePosition;
        NullableValue value = argumentType.getColumnValue(udtValue, tuplePosition, () -> udtValue.getType().getFieldType(fieldNames[finalTuplePosition]));
        writeNativeValue(argumentType.getTrinoType(), singleRowBlockWriter, value.getValue());
        tuplePosition++;
    }
    blockBuilder.closeEntry();
    return (Block) this.trinoType.getObject(blockBuilder, 0);
}
Also used : UDTValue(com.datastax.driver.core.UDTValue) RowBlockBuilder(io.trino.spi.block.RowBlockBuilder) NullableValue(io.trino.spi.predicate.NullableValue) Block(io.trino.spi.block.Block) InetAddresses.toAddrString(com.google.common.net.InetAddresses.toAddrString) SingleRowBlockWriter(io.trino.spi.block.SingleRowBlockWriter)

Aggregations

SingleRowBlockWriter (io.trino.spi.block.SingleRowBlockWriter)6 RowBlockBuilder (io.trino.spi.block.RowBlockBuilder)4 Block (io.trino.spi.block.Block)3 NullableValue (io.trino.spi.predicate.NullableValue)2 TupleValue (com.datastax.driver.core.TupleValue)1 UDTValue (com.datastax.driver.core.UDTValue)1 InetAddresses.toAddrString (com.google.common.net.InetAddresses.toAddrString)1 Benchmark (org.openjdk.jmh.annotations.Benchmark)1 Test (org.testng.annotations.Test)1