use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TestMergeHyperLogLogAggregation method getSequenceBlocks.
@Override
public Block[] getSequenceBlocks(int start, int length) {
BlockBuilder blockBuilder = HYPER_LOG_LOG.createBlockBuilder(new BlockBuilderStatus(), length);
for (int i = start; i < start + length; i++) {
HyperLogLog hll = HyperLogLog.newInstance(NUMBER_OF_BUCKETS);
hll.add(i);
HYPER_LOG_LOG.writeSlice(blockBuilder, hll.serialize());
}
return new Block[] { blockBuilder.build() };
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TestMapAggAggregation method testDoubleRowMap.
@Test
public void testDoubleRowMap() throws Exception {
RowType innerRowType = new RowType(ImmutableList.of(INTEGER, DOUBLE), Optional.of(ImmutableList.of("f1", "f2")));
MapType mapType = new MapType(DOUBLE, innerRowType);
InternalAggregationFunction aggFunc = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(NAME, AGGREGATE, mapType.getTypeSignature(), parseTypeSignature(StandardTypes.DOUBLE), innerRowType.getTypeSignature()));
BlockBuilder builder = innerRowType.createBlockBuilder(new BlockBuilderStatus(), 3);
innerRowType.writeObject(builder, toRow(ImmutableList.of(INTEGER, DOUBLE), 1L, 1.0));
innerRowType.writeObject(builder, toRow(ImmutableList.of(INTEGER, DOUBLE), 2L, 2.0));
innerRowType.writeObject(builder, toRow(ImmutableList.of(INTEGER, DOUBLE), 3L, 3.0));
assertAggregation(aggFunc, ImmutableMap.of(1.0, ImmutableList.of(1, 1.0), 2.0, ImmutableList.of(2, 2.0), 3.0, ImmutableList.of(3, 3.0)), createDoublesBlock(1.0, 2.0, 3.0), builder.build());
}
use of com.facebook.presto.spi.block.BlockBuilder 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.BlockBuilder in project presto by prestodb.
the class ArrayUnnester method appendTo.
protected void appendTo(PageBuilder pageBuilder, int outputChannelOffset) {
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(outputChannelOffset);
elementType.appendTo(arrayBlock, position, blockBuilder);
position++;
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class HashSemiJoinOperator method addInput.
@Override
public void addInput(Page page) {
requireNonNull(page, "page is null");
checkState(!finishing, "Operator is finishing");
checkState(channelSet != null, "Set has not been built yet");
checkState(outputPage == null, "Operator still has pending output");
// create the block builder for the new boolean column
// we know the exact size required for the block
BlockBuilder blockBuilder = BOOLEAN.createFixedSizeBlockBuilder(page.getPositionCount());
Page probeJoinPage = new Page(page.getBlock(probeJoinChannel));
// update hashing strategy to use probe cursor
for (int position = 0; position < page.getPositionCount(); position++) {
if (probeJoinPage.getBlock(0).isNull(position)) {
throw new PrestoException(NOT_SUPPORTED, "NULL values are not allowed on the probe side of SemiJoin operator. See the query plan for details.");
} else {
boolean contains = channelSet.contains(position, probeJoinPage);
if (!contains && channelSet.containsNull()) {
blockBuilder.appendNull();
} else {
BOOLEAN.writeBoolean(blockBuilder, contains);
}
}
}
// add the new boolean column to the page
Block[] sourceBlocks = page.getBlocks();
// +1 for the single boolean output channel
Block[] outputBlocks = new Block[sourceBlocks.length + 1];
System.arraycopy(sourceBlocks, 0, outputBlocks, 0, sourceBlocks.length);
outputBlocks[sourceBlocks.length] = blockBuilder.build();
outputPage = new Page(outputBlocks);
}
Aggregations