use of com.facebook.presto.operator.aggregation.state.VarianceState in project presto by prestodb.
the class TestStateCompiler method testVarianceStateSerialization.
@Test
public void testVarianceStateSerialization() {
AccumulatorStateFactory<VarianceState> factory = StateCompiler.generateStateFactory(VarianceState.class);
AccumulatorStateSerializer<VarianceState> serializer = StateCompiler.generateStateSerializer(VarianceState.class);
VarianceState singleState = factory.createSingleState();
VarianceState deserializedState = factory.createSingleState();
singleState.setMean(1);
singleState.setCount(2);
singleState.setM2(3);
BlockBuilder builder = new RowType(ImmutableList.of(BIGINT, DOUBLE, DOUBLE), Optional.empty()).createBlockBuilder(new BlockBuilderStatus(), 1);
serializer.serialize(singleState, builder);
Block block = builder.build();
serializer.deserialize(block, 0, deserializedState);
assertEquals(deserializedState.getCount(), singleState.getCount());
assertEquals(deserializedState.getMean(), singleState.getMean());
assertEquals(deserializedState.getM2(), singleState.getM2());
}
Aggregations