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();
}
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);
}
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);
}
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());
}
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();
}
Aggregations