Search in sources :

Example 1 with LongState

use of com.facebook.presto.operator.aggregation.state.LongState in project presto by prestodb.

the class TestStateCompiler method testPrimitiveLongSerialization.

@Test
public void testPrimitiveLongSerialization() {
    AccumulatorStateFactory<LongState> factory = StateCompiler.generateStateFactory(LongState.class);
    AccumulatorStateSerializer<LongState> serializer = StateCompiler.generateStateSerializer(LongState.class);
    LongState state = factory.createSingleState();
    LongState deserializedState = factory.createSingleState();
    state.setLong(2);
    BlockBuilder builder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), 1);
    serializer.serialize(state, builder);
    Block block = builder.build();
    assertEquals(BIGINT.getLong(block, 0), state.getLong());
    serializer.deserialize(block, 0, deserializedState);
    assertEquals(deserializedState.getLong(), state.getLong());
}
Also used : Block(com.facebook.presto.spi.block.Block) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) NullableLongState(com.facebook.presto.operator.aggregation.state.NullableLongState) LongState(com.facebook.presto.operator.aggregation.state.LongState) 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 2 with LongState

use of com.facebook.presto.operator.aggregation.state.LongState in project presto by prestodb.

the class CountColumn method generateAggregation.

private static InternalAggregationFunction generateAggregation(Type type) {
    DynamicClassLoader classLoader = new DynamicClassLoader(CountColumn.class.getClassLoader());
    AccumulatorStateSerializer<LongState> stateSerializer = StateCompiler.generateStateSerializer(LongState.class, classLoader);
    AccumulatorStateFactory<LongState> stateFactory = StateCompiler.generateStateFactory(LongState.class, classLoader);
    Type intermediateType = stateSerializer.getSerializedType();
    List<Type> inputTypes = ImmutableList.of(type);
    AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, BIGINT.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(type), INPUT_FUNCTION, COMBINE_FUNCTION, OUTPUT_FUNCTION, LongState.class, stateSerializer, stateFactory, BIGINT);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(NAME, inputTypes, intermediateType, BIGINT, true, factory);
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) Type(com.facebook.presto.spi.type.Type) LongState(com.facebook.presto.operator.aggregation.state.LongState)

Aggregations

LongState (com.facebook.presto.operator.aggregation.state.LongState)2 BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)1 DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)1 NullableLongState (com.facebook.presto.operator.aggregation.state.NullableLongState)1 Block (com.facebook.presto.spi.block.Block)1 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)1 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)1 InterleavedBlockBuilder (com.facebook.presto.spi.block.InterleavedBlockBuilder)1 Type (com.facebook.presto.spi.type.Type)1 Test (org.testng.annotations.Test)1