use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TestStateCompiler method testNonPrimitiveSerialization.
@Test
public void testNonPrimitiveSerialization() {
AccumulatorStateFactory<SliceState> factory = StateCompiler.generateStateFactory(SliceState.class);
AccumulatorStateSerializer<SliceState> serializer = StateCompiler.generateStateSerializer(SliceState.class);
SliceState state = factory.createSingleState();
SliceState deserializedState = factory.createSingleState();
state.setSlice(null);
BlockBuilder nullBlockBuilder = VARCHAR.createBlockBuilder(new BlockBuilderStatus(), 1);
serializer.serialize(state, nullBlockBuilder);
Block nullBlock = nullBlockBuilder.build();
serializer.deserialize(nullBlock, 0, deserializedState);
assertEquals(deserializedState.getSlice(), state.getSlice());
state.setSlice(utf8Slice("test"));
BlockBuilder builder = VARCHAR.createBlockBuilder(new BlockBuilderStatus(), 1);
serializer.serialize(state, builder);
Block block = builder.build();
serializer.deserialize(block, 0, deserializedState);
assertEquals(deserializedState.getSlice(), state.getSlice());
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TestTypedHeap method test.
private static void test(IntStream inputStream, BlockComparator comparator, PrimitiveIterator.OfInt outputIterator) {
BlockBuilder blockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), INPUT_SIZE);
inputStream.forEach(x -> BIGINT.writeLong(blockBuilder, x));
TypedHeap heap = new TypedHeap(comparator, BIGINT, OUTPUT_SIZE);
heap.addAll(blockBuilder);
BlockBuilder resultBlockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), OUTPUT_SIZE);
heap.popAll(resultBlockBuilder);
Block resultBlock = resultBlockBuilder.build();
assertEquals(resultBlock.getPositionCount(), OUTPUT_SIZE);
for (int i = 0; i < OUTPUT_SIZE; i++) {
assertEquals(BIGINT.getLong(resultBlock, i), outputIterator.nextInt());
}
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TestDecimalAverageAggregation method addToState.
private static void addToState(LongDecimalWithOverflowAndLongState state, BigInteger value) {
BlockBuilder blockBuilder = TYPE.createFixedSizeBlockBuilder(1);
TYPE.writeSlice(blockBuilder, unscaledDecimal(value));
DecimalAverageAggregation.inputLongDecimal(TYPE, state, blockBuilder.build(), 0);
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TestDecimalSumAggregation method addToState.
private static void addToState(LongDecimalWithOverflowState state, BigInteger value) {
BlockBuilder blockBuilder = TYPE.createFixedSizeBlockBuilder(1);
TYPE.writeSlice(blockBuilder, unscaledDecimal(value));
DecimalSumAggregation.inputLongDecimal(TYPE, state, blockBuilder.build(), 0);
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TestMapAggAggregation method testDoubleMapMap.
@Test
public void testDoubleMapMap() throws Exception {
MapType innerMapType = new MapType(VARCHAR, VARCHAR);
MapType mapType = new MapType(DOUBLE, innerMapType);
InternalAggregationFunction aggFunc = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(NAME, AGGREGATE, mapType.getTypeSignature(), parseTypeSignature(StandardTypes.DOUBLE), innerMapType.getTypeSignature()));
BlockBuilder builder = innerMapType.createBlockBuilder(new BlockBuilderStatus(), 3);
innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("a", "b")));
innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("c", "d")));
innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("e", "f")));
assertAggregation(aggFunc, ImmutableMap.of(1.0, ImmutableMap.of("a", "b"), 2.0, ImmutableMap.of("c", "d"), 3.0, ImmutableMap.of("e", "f")), createDoublesBlock(1.0, 2.0, 3.0), builder.build());
}
Aggregations