Search in sources :

Example 1 with MapUnionSumState

use of com.facebook.presto.operator.aggregation.state.MapUnionSumState in project presto by prestodb.

the class TestMapUnionSumResult method testAddToKeySet.

@Test
public void testAddToKeySet() {
    MapType mapType = createMapType(BIGINT, BIGINT);
    Map<Long, Long> map = new HashMap<>();
    map.put(1L, 1L);
    MapBlock mapBlock = (MapBlock) createMapBlock(mapType, map);
    Block singleMapBlock = mapBlock.getBlock(0);
    MapUnionSumState mapUnionSumState = new MapUnionSumStateFactory(BIGINT, BIGINT).createSingleState();
    MapUnionSumResult mapUnionSumResult = MapUnionSumResult.create(BIGINT, BIGINT, mapUnionSumState.getAdder(), singleMapBlock);
    TypedSet typedSet = new TypedSet(BIGINT, 1, "TEST");
    Block block = createLongsBlock(-1);
    typedSet.add(block, 0);
    assertEquals(typedSet.size(), 1);
    assertEquals(mapUnionSumResult.size(), 1);
    mapUnionSumResult.unionSum(mapUnionSumResult).addKeyToSet(typedSet, 0);
    assertEquals(typedSet.size(), 2);
    assertEquals(mapUnionSumResult.size(), 1);
}
Also used : MapUnionSumStateFactory(com.facebook.presto.operator.aggregation.state.MapUnionSumStateFactory) HashMap(java.util.HashMap) MapUnionSumState(com.facebook.presto.operator.aggregation.state.MapUnionSumState) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) MapBlock(com.facebook.presto.common.block.MapBlock) BlockAssertions.createMapBlock(com.facebook.presto.block.BlockAssertions.createMapBlock) Block(com.facebook.presto.common.block.Block) MapBlock(com.facebook.presto.common.block.MapBlock) BlockAssertions.createMapBlock(com.facebook.presto.block.BlockAssertions.createMapBlock) BlockAssertions.createMapType(com.facebook.presto.block.BlockAssertions.createMapType) MapType(com.facebook.presto.common.type.MapType) Test(org.testng.annotations.Test)

Aggregations

BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)1 BlockAssertions.createMapBlock (com.facebook.presto.block.BlockAssertions.createMapBlock)1 BlockAssertions.createMapType (com.facebook.presto.block.BlockAssertions.createMapType)1 Block (com.facebook.presto.common.block.Block)1 MapBlock (com.facebook.presto.common.block.MapBlock)1 MapType (com.facebook.presto.common.type.MapType)1 MapUnionSumState (com.facebook.presto.operator.aggregation.state.MapUnionSumState)1 MapUnionSumStateFactory (com.facebook.presto.operator.aggregation.state.MapUnionSumStateFactory)1 HashMap (java.util.HashMap)1 Test (org.testng.annotations.Test)1