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());
}
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);
}
Aggregations