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