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