Search in sources :

Example 1 with SingleRowBlockWriter

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

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

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

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

the class BenchmarkRowBlockBuilder method benchmarkBeginBlockEntry.

@Benchmark
public void benchmarkBeginBlockEntry(BenchmarkData data, Blackhole blackhole) {
    for (int i = 0; i < data.rows; i++) {
        SingleRowBlockWriter singleRowBlockWriter = data.getBlockBuilder().beginBlockEntry();
        for (int fieldIndex = 0; fieldIndex < data.getTypes().size(); fieldIndex++) {
            singleRowBlockWriter.writeLong(data.getRandom().nextLong()).closeEntry();
        }
        blackhole.consume(singleRowBlockWriter);
        data.getBlockBuilder().closeEntry();
    }
    blackhole.consume(data.getBlockBuilder());
}
Also used : SingleRowBlockWriter(io.trino.spi.block.SingleRowBlockWriter) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 5 with SingleRowBlockWriter

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

the class TestSingleRowBlockWriter method testGetSizeInBytes.

@Test
public void testGetSizeInBytes() {
    SingleRowBlockWriter singleRowBlockWriter = rowBlockBuilder.beginBlockEntry();
    // Test whether new singleRowBlockWriter has size equal to 0
    assertEquals(0, singleRowBlockWriter.getSizeInBytes());
    singleRowBlockWriter.writeLong(10).closeEntry();
    assertEquals(9, singleRowBlockWriter.getSizeInBytes());
    singleRowBlockWriter.writeByte(10).closeEntry();
    assertEquals(11, singleRowBlockWriter.getSizeInBytes());
    rowBlockBuilder.closeEntry();
    // Test whether previous entry does not mix to the next entry (for size). Does reset works on size?
    singleRowBlockWriter = rowBlockBuilder.beginBlockEntry();
    assertEquals(0, singleRowBlockWriter.getSizeInBytes());
    singleRowBlockWriter.writeLong(10).closeEntry();
    assertEquals(9, singleRowBlockWriter.getSizeInBytes());
    singleRowBlockWriter.writeByte(10).closeEntry();
    assertEquals(11, singleRowBlockWriter.getSizeInBytes());
    rowBlockBuilder.closeEntry();
}
Also used : SingleRowBlockWriter(io.trino.spi.block.SingleRowBlockWriter) Test(org.testng.annotations.Test)

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