use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class MultiKeyValuePairs method serialize.
public void serialize(BlockBuilder out) {
BlockBuilder arrayBlockBuilder = out.beginBlockEntry();
for (int i = 0; i < keyBlockBuilder.getPositionCount(); i++) {
BlockBuilder rowBlockBuilder = arrayBlockBuilder.beginBlockEntry();
keyType.appendTo(keyBlockBuilder, i, rowBlockBuilder);
valueType.appendTo(valueBlockBuilder, i, rowBlockBuilder);
arrayBlockBuilder.closeEntry();
}
out.closeEntry();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class ArrayAggregationStateSerializer method deserialize.
@Override
public void deserialize(Block block, int index, ArrayAggregationState state) {
Block stateBlock = (Block) arrayType.getObject(block, index);
int positionCount = stateBlock.getPositionCount();
BlockBuilder blockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), positionCount);
for (int i = 0; i < positionCount; i++) {
elementType.appendTo(stateBlock, i, blockBuilder);
}
state.setBlockBuilder(blockBuilder);
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class ApproximateDoublePercentileArrayAggregations method output.
@OutputFunction("array(double)")
public static void output(@AggregationState DigestAndPercentileArrayState state, BlockBuilder out) {
QuantileDigest digest = state.getDigest();
List<Double> percentiles = state.getPercentiles();
if (percentiles == null || digest == null) {
out.appendNull();
return;
}
BlockBuilder blockBuilder = out.beginBlockEntry();
for (int i = 0; i < percentiles.size(); i++) {
Double percentile = percentiles.get(i);
DOUBLE.writeDouble(blockBuilder, sortableLongToDouble(digest.getQuantile(percentile)));
}
out.closeEntry();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class ArrayUnionFunction method bigintUnion.
@SqlType("array(bigint)")
public static Block bigintUnion(@SqlType("array(bigint)") Block leftArray, @SqlType("array(bigint)") Block rightArray) {
int leftArrayCount = leftArray.getPositionCount();
int rightArrayCount = rightArray.getPositionCount();
LongSet set = new LongOpenHashSet(leftArrayCount + rightArrayCount);
BlockBuilder distinctElementBlockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), leftArrayCount + rightArrayCount);
AtomicBoolean containsNull = new AtomicBoolean(false);
appendBigintArray(leftArray, containsNull, set, distinctElementBlockBuilder);
appendBigintArray(rightArray, containsNull, set, distinctElementBlockBuilder);
return distinctElementBlockBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TupleFilterProcessor method processColumnar.
@Override
public Page processColumnar(ConnectorSession session, Page page, List<? extends Type> types) {
PageBuilder pageBuilder = new PageBuilder(types);
int positionCount = page.getPositionCount();
int[] selectedPositions = new int[positionCount];
int selectedCount = 0;
for (int i = 0; i < positionCount; i++) {
if (matches(i, page)) {
selectedPositions[selectedCount++] = i;
}
}
for (int i = 0; i < outputTypes.size(); i++) {
Type type = outputTypes.get(i);
Block block = page.getBlock(i);
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(i);
for (int position : selectedPositions) {
type.appendTo(block, position, blockBuilder);
}
}
pageBuilder.declarePositions(selectedCount);
return pageBuilder.build();
}
Aggregations