Search in sources :

Example 6 with RowBlockBuilder

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

the class OperatorAssertion method toRow.

public static Block toRow(List<Type> parameterTypes, Object... values) {
    checkArgument(parameterTypes.size() == values.length, "parameterTypes.size(" + parameterTypes.size() + ") does not equal to values.length(" + values.length + ")");
    RowType rowType = RowType.anonymous(parameterTypes);
    BlockBuilder blockBuilder = new RowBlockBuilder(parameterTypes, null, 1);
    BlockBuilder singleRowBlockWriter = blockBuilder.beginBlockEntry();
    for (int i = 0; i < values.length; i++) {
        appendToBlockBuilder(parameterTypes.get(i), values[i], singleRowBlockWriter);
    }
    blockBuilder.closeEntry();
    return rowType.getObject(blockBuilder, 0);
}
Also used : RowBlockBuilder(io.trino.spi.block.RowBlockBuilder) RowType(io.trino.spi.type.RowType) StructuralTestUtil.appendToBlockBuilder(io.trino.util.StructuralTestUtil.appendToBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder) RowBlockBuilder(io.trino.spi.block.RowBlockBuilder)

Example 7 with RowBlockBuilder

use of io.trino.spi.block.RowBlockBuilder 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

RowBlockBuilder (io.trino.spi.block.RowBlockBuilder)7 Block (io.trino.spi.block.Block)4 SingleRowBlockWriter (io.trino.spi.block.SingleRowBlockWriter)4 BlockBuilder (io.trino.spi.block.BlockBuilder)3 NullableValue (io.trino.spi.predicate.NullableValue)2 RowType (io.trino.spi.type.RowType)2 TupleValue (com.datastax.driver.core.TupleValue)1 UDTValue (com.datastax.driver.core.UDTValue)1 InetAddresses.toAddrString (com.google.common.net.InetAddresses.toAddrString)1 Slice (io.airlift.slice.Slice)1 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)1 ArrayBlock.fromElementBlock (io.trino.spi.block.ArrayBlock.fromElementBlock)1 DictionaryBlock (io.trino.spi.block.DictionaryBlock)1 RowBlock (io.trino.spi.block.RowBlock)1 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)1 ArrayType (io.trino.spi.type.ArrayType)1 CharType (io.trino.spi.type.CharType)1 DecimalType (io.trino.spi.type.DecimalType)1 MapType (io.trino.spi.type.MapType)1 TimestampType (io.trino.spi.type.TimestampType)1