use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class ParquetReader method rewriteLongArrayBlock.
private static Block rewriteLongArrayBlock(LongArrayBlock longArrayBlock, Type targetType) {
int positionCount = longArrayBlock.getPositionCount();
BlockBuilder newBlockBuilder = targetType.createBlockBuilder(null, positionCount);
for (int position = 0; position < positionCount; position++) {
if (longArrayBlock.isNull(position)) {
newBlockBuilder.appendNull();
} else {
targetType.writeLong(newBlockBuilder, longArrayBlock.getLong(position, 0));
}
}
return newBlockBuilder.build();
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class AbstractColumnReader method readNext.
@Override
public ColumnChunk readNext() {
IntList definitionLevels = new IntArrayList();
IntList repetitionLevels = new IntArrayList();
seek();
BlockBuilder blockBuilder = field.getType().createBlockBuilder(null, nextBatchSize);
int valueCount = 0;
while (valueCount < nextBatchSize) {
if (page == null) {
readNextPage();
}
int valuesToRead = Math.min(remainingValueCountInPage, nextBatchSize - valueCount);
if (valuesToRead == 0) {
// When we break here, we could end up with valueCount < nextBatchSize, this is because we may skip reading values in readValues()
break;
}
readValues(blockBuilder, valuesToRead, field.getType(), definitionLevels, repetitionLevels);
valueCount += valuesToRead;
}
readOffset = 0;
nextBatchSize = 0;
return new ColumnChunk(blockBuilder.build(), definitionLevels.toIntArray(), repetitionLevels.toIntArray());
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class StructuralTestUtil method rowBlockOf.
public static Block rowBlockOf(List<Type> parameterTypes, Object... values) {
RowType rowType = RowType.anonymous(parameterTypes);
BlockBuilder blockBuilder = rowType.createBlockBuilder(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);
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class StructuralTestUtil method mapBlockOf.
public static Block mapBlockOf(Type keyType, Type valueType, Object[] keys, Object[] values) {
checkArgument(keys.length == values.length, "keys/values must have the same length");
MapType mapType = mapType(keyType, valueType);
BlockBuilder blockBuilder = mapType.createBlockBuilder(null, 10);
BlockBuilder singleMapBlockWriter = blockBuilder.beginBlockEntry();
for (int i = 0; i < keys.length; i++) {
Object key = keys[i];
Object value = values[i];
appendToBlockBuilder(keyType, key, singleMapBlockWriter);
appendToBlockBuilder(valueType, value, singleMapBlockWriter);
}
blockBuilder.closeEntry();
return mapType.getObject(blockBuilder, 0);
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class TestLearnAggregations method assertLearnClassifer.
private static void assertLearnClassifer(Accumulator accumulator) {
accumulator.addInput(getPage());
BlockBuilder finalOut = accumulator.getFinalType().createBlockBuilder(null, 1);
accumulator.evaluateFinal(finalOut);
Block block = finalOut.build();
Slice slice = accumulator.getFinalType().getSlice(block, 0);
Model deserialized = ModelUtils.deserialize(slice);
assertNotNull(deserialized, "deserialization failed");
assertTrue(deserialized instanceof Classifier, "deserialized model is not a classifier");
}
Aggregations