Search in sources :

Example 1 with LongState

use of io.prestosql.operator.aggregation.state.LongState in project hetu-core by openlookeng.

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(null, 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(io.prestosql.spi.block.Block) BlockAssertions.createLongsBlock(io.prestosql.block.BlockAssertions.createLongsBlock) LongState(io.prestosql.operator.aggregation.state.LongState) NullableLongState(io.prestosql.operator.aggregation.state.NullableLongState) BlockBuilder(io.prestosql.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 2 with LongState

use of io.prestosql.operator.aggregation.state.LongState in project hetu-core by openlookeng.

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, ImmutableList.of(new AccumulatorStateDescriptor(LongState.class, stateSerializer, stateFactory)), BIGINT);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), BIGINT, true, false, factory);
}
Also used : DynamicClassLoader(io.airlift.bytecode.DynamicClassLoader) Type(io.prestosql.spi.type.Type) AccumulatorStateDescriptor(io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) LongState(io.prestosql.operator.aggregation.state.LongState)

Aggregations

LongState (io.prestosql.operator.aggregation.state.LongState)2 DynamicClassLoader (io.airlift.bytecode.DynamicClassLoader)1 BlockAssertions.createLongsBlock (io.prestosql.block.BlockAssertions.createLongsBlock)1 AccumulatorStateDescriptor (io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor)1 NullableLongState (io.prestosql.operator.aggregation.state.NullableLongState)1 Block (io.prestosql.spi.block.Block)1 BlockBuilder (io.prestosql.spi.block.BlockBuilder)1 Type (io.prestosql.spi.type.Type)1 Test (org.testng.annotations.Test)1