Search in sources :

Example 46 with BlockBuilder

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());
}
Also used : Block(com.facebook.presto.spi.block.Block) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) Test(org.testng.annotations.Test)

Example 47 with BlockBuilder

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());
    }
}
Also used : Block(com.facebook.presto.spi.block.Block) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 48 with BlockBuilder

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);
}
Also used : BlockBuilder(com.facebook.presto.spi.block.BlockBuilder)

Example 49 with BlockBuilder

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);
}
Also used : VariableWidthBlockBuilder(com.facebook.presto.spi.block.VariableWidthBlockBuilder) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder)

Example 50 with BlockBuilder

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());
}
Also used : Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) MapType(com.facebook.presto.type.MapType) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) Test(org.testng.annotations.Test)

Aggregations

BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)290 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)211 Block (com.facebook.presto.spi.block.Block)56 Slice (io.airlift.slice.Slice)53 InterleavedBlockBuilder (com.facebook.presto.spi.block.InterleavedBlockBuilder)39 Test (org.testng.annotations.Test)38 Type (com.facebook.presto.spi.type.Type)33 SqlType (com.facebook.presto.spi.function.SqlType)24 ArrayType (com.facebook.presto.type.ArrayType)19 Page (com.facebook.presto.spi.Page)18 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)17 TypeParameter (com.facebook.presto.spi.function.TypeParameter)15 MapType (com.facebook.presto.type.MapType)14 RowType (com.facebook.presto.type.RowType)14 TypeJsonUtils.appendToBlockBuilder (com.facebook.presto.type.TypeJsonUtils.appendToBlockBuilder)13 PageBuilder (com.facebook.presto.spi.PageBuilder)12 ImmutableList (com.google.common.collect.ImmutableList)12 PrestoException (com.facebook.presto.spi.PrestoException)11 RunLengthEncodedBlock (com.facebook.presto.spi.block.RunLengthEncodedBlock)11 DictionaryBlock (com.facebook.presto.spi.block.DictionaryBlock)10