use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
the class AccumuloRowSerializer method getBlockFromMap.
/**
* Encodes the given map into a Block.
*
* @param mapType Presto type of the map
* @param map Map of key/value pairs to encode
* @return Presto Block
*/
static Block getBlockFromMap(Type mapType, Map<?, ?> map) {
Type keyType = mapType.getTypeParameters().get(0);
Type valueType = mapType.getTypeParameters().get(1);
BlockBuilder builder = new InterleavedBlockBuilder(ImmutableList.of(keyType, valueType), new BlockBuilderStatus(), map.size() * 2);
for (Entry<?, ?> entry : map.entrySet()) {
writeObject(builder, keyType, entry.getKey());
writeObject(builder, valueType, entry.getValue());
}
return builder.build();
}
use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
the class MarkDistinctHash method markDistinctRows.
public Block markDistinctRows(Page page) {
GroupByIdBlock ids = groupByHash.getGroupIds(page);
BlockBuilder blockBuilder = BOOLEAN.createBlockBuilder(new BlockBuilderStatus(), ids.getPositionCount());
for (int i = 0; i < ids.getPositionCount(); i++) {
if (ids.getGroupId(i) == nextDistinctId) {
BOOLEAN.writeBoolean(blockBuilder, true);
nextDistinctId++;
} else {
BOOLEAN.writeBoolean(blockBuilder, false);
}
}
return blockBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
the class DoubleHistogramAggregation method output.
@OutputFunction("map(double,double)")
public static void output(@AggregationState State state, BlockBuilder out) {
if (state.get() == null) {
out.appendNull();
} else {
Map<Double, Double> value = state.get().getBuckets();
BlockBuilder blockBuilder = DoubleType.DOUBLE.createBlockBuilder(new BlockBuilderStatus(), value.size() * 2);
for (Map.Entry<Double, Double> entry : value.entrySet()) {
DoubleType.DOUBLE.writeDouble(blockBuilder, entry.getKey());
DoubleType.DOUBLE.writeDouble(blockBuilder, entry.getValue());
}
Block block = blockBuilder.build();
out.writeObject(block);
out.closeEntry();
}
}
use of com.facebook.presto.spi.block.BlockBuilderStatus 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.BlockBuilderStatus 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();
}
Aggregations