Search in sources :

Example 1 with VarianceState

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());
}
Also used : VarianceState(com.facebook.presto.operator.aggregation.state.VarianceState) RowType(com.facebook.presto.type.RowType) Block(com.facebook.presto.spi.block.Block) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) 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)

Aggregations

BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)1 VarianceState (com.facebook.presto.operator.aggregation.state.VarianceState)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 RowType (com.facebook.presto.type.RowType)1 Test (org.testng.annotations.Test)1