Search in sources :

Example 1 with RowBlockBuilder

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

the class TestSimpleRowType method createTestBlock.

private static Block createTestBlock() {
    RowBlockBuilder blockBuilder = (RowBlockBuilder) TYPE.createBlockBuilder(null, 3);
    SingleRowBlockWriter singleRowBlockWriter;
    singleRowBlockWriter = blockBuilder.beginBlockEntry();
    BIGINT.writeLong(singleRowBlockWriter, 1);
    VARCHAR.writeSlice(singleRowBlockWriter, utf8Slice("cat"));
    blockBuilder.closeEntry();
    singleRowBlockWriter = blockBuilder.beginBlockEntry();
    BIGINT.writeLong(singleRowBlockWriter, 2);
    VARCHAR.writeSlice(singleRowBlockWriter, utf8Slice("cats"));
    blockBuilder.closeEntry();
    singleRowBlockWriter = blockBuilder.beginBlockEntry();
    BIGINT.writeLong(singleRowBlockWriter, 3);
    VARCHAR.writeSlice(singleRowBlockWriter, utf8Slice("dog"));
    blockBuilder.closeEntry();
    return blockBuilder.build();
}
Also used : RowBlockBuilder(io.trino.spi.block.RowBlockBuilder) SingleRowBlockWriter(io.trino.spi.block.SingleRowBlockWriter)

Example 2 with RowBlockBuilder

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

the class TestSimpleRowType method getGreaterValue.

@Override
protected Object getGreaterValue(Object value) {
    RowBlockBuilder blockBuilder = (RowBlockBuilder) TYPE.createBlockBuilder(null, 1);
    SingleRowBlockWriter singleRowBlockWriter;
    Block block = (Block) value;
    singleRowBlockWriter = blockBuilder.beginBlockEntry();
    BIGINT.writeLong(singleRowBlockWriter, block.getSingleValueBlock(0).getLong(0, 0) + 1);
    VARCHAR.writeSlice(singleRowBlockWriter, block.getSingleValueBlock(1).getSlice(0, 0, 1));
    blockBuilder.closeEntry();
    return TYPE.getObject(blockBuilder.build(), 0);
}
Also used : RowBlockBuilder(io.trino.spi.block.RowBlockBuilder) Block(io.trino.spi.block.Block) SingleRowBlockWriter(io.trino.spi.block.SingleRowBlockWriter)

Example 3 with RowBlockBuilder

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

the class CassandraType method buildTupleValue.

private Block buildTupleValue(GettableByIndexData row, int position) {
    verify(this.kind == Kind.TUPLE, "Not a TUPLE type");
    TupleValue tupleValue = row.getTupleValue(position);
    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(tupleValue, tuplePosition, () -> tupleValue.getType().getComponentTypes().get(finalTuplePosition));
        writeNativeValue(argumentType.getTrinoType(), singleRowBlockWriter, value.getValue());
        tuplePosition++;
    }
    // can I just return singleRowBlockWriter here? It extends AbstractSingleRowBlock and tests pass.
    blockBuilder.closeEntry();
    return (Block) this.trinoType.getObject(blockBuilder, 0);
}
Also used : RowBlockBuilder(io.trino.spi.block.RowBlockBuilder) NullableValue(io.trino.spi.predicate.NullableValue) Block(io.trino.spi.block.Block) SingleRowBlockWriter(io.trino.spi.block.SingleRowBlockWriter) TupleValue(com.datastax.driver.core.TupleValue)

Example 4 with RowBlockBuilder

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

the class BlockAssertions method createRowBlock.

public static Block createRowBlock(List<Type> fieldTypes, Object[]... rows) {
    BlockBuilder rowBlockBuilder = new RowBlockBuilder(fieldTypes, null, 1);
    for (Object[] row : rows) {
        if (row == null) {
            rowBlockBuilder.appendNull();
            continue;
        }
        verify(row.length == fieldTypes.size());
        BlockBuilder singleRowBlockWriter = rowBlockBuilder.beginBlockEntry();
        for (int fieldIndex = 0; fieldIndex < fieldTypes.size(); fieldIndex++) {
            Type fieldType = fieldTypes.get(fieldIndex);
            Object fieldValue = row[fieldIndex];
            if (fieldValue == null) {
                singleRowBlockWriter.appendNull();
                continue;
            }
            if (fieldValue instanceof String) {
                fieldType.writeSlice(singleRowBlockWriter, utf8Slice((String) fieldValue));
            } else if (fieldValue instanceof Slice) {
                fieldType.writeSlice(singleRowBlockWriter, (Slice) fieldValue);
            } else if (fieldValue instanceof Double) {
                fieldType.writeDouble(singleRowBlockWriter, (Double) fieldValue);
            } else if (fieldValue instanceof Long) {
                fieldType.writeLong(singleRowBlockWriter, (Long) fieldValue);
            } else if (fieldValue instanceof Boolean) {
                fieldType.writeBoolean(singleRowBlockWriter, (Boolean) fieldValue);
            } else if (fieldValue instanceof Block) {
                fieldType.writeObject(singleRowBlockWriter, fieldValue);
            } else if (fieldValue instanceof Integer) {
                fieldType.writeLong(singleRowBlockWriter, (Integer) fieldValue);
            } else {
                throw new IllegalArgumentException();
            }
        }
        rowBlockBuilder.closeEntry();
    }
    return rowBlockBuilder.build();
}
Also used : RowBlockBuilder(io.trino.spi.block.RowBlockBuilder) BigInteger(java.math.BigInteger) RowType(io.trino.spi.type.RowType) ArrayType(io.trino.spi.type.ArrayType) DecimalType(io.trino.spi.type.DecimalType) Type(io.trino.spi.type.Type) TimestampType(io.trino.spi.type.TimestampType) MapType(io.trino.spi.type.MapType) CharType(io.trino.spi.type.CharType) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Slice(io.airlift.slice.Slice) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) ArrayBlock.fromElementBlock(io.trino.spi.block.ArrayBlock.fromElementBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) RowBlock(io.trino.spi.block.RowBlock) BlockBuilder(io.trino.spi.block.BlockBuilder) RowBlockBuilder(io.trino.spi.block.RowBlockBuilder)

Example 5 with RowBlockBuilder

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

the class TestRowBlock method createBlockBuilderWithValues.

private BlockBuilder createBlockBuilderWithValues(List<Type> fieldTypes, List<Object>[] rows) {
    BlockBuilder rowBlockBuilder = new RowBlockBuilder(fieldTypes, null, 1);
    for (List<Object> row : rows) {
        if (row == null) {
            rowBlockBuilder.appendNull();
        } else {
            BlockBuilder singleRowBlockWriter = rowBlockBuilder.beginBlockEntry();
            for (Object fieldValue : row) {
                if (fieldValue == null) {
                    singleRowBlockWriter.appendNull();
                } else {
                    if (fieldValue instanceof Long) {
                        BIGINT.writeLong(singleRowBlockWriter, ((Long) fieldValue).longValue());
                    } else if (fieldValue instanceof String) {
                        VARCHAR.writeSlice(singleRowBlockWriter, utf8Slice((String) fieldValue));
                    } else {
                        throw new IllegalArgumentException();
                    }
                }
            }
            rowBlockBuilder.closeEntry();
        }
    }
    return rowBlockBuilder;
}
Also used : RowBlockBuilder(io.trino.spi.block.RowBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder) RowBlockBuilder(io.trino.spi.block.RowBlockBuilder)

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