Search in sources :

Example 1 with MapUnionSumStateFactory

use of com.facebook.presto.operator.aggregation.state.MapUnionSumStateFactory 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)

Example 2 with MapUnionSumStateFactory

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

the class MapUnionSumAggregation method generateAggregation.

private static InternalAggregationFunction generateAggregation(Type keyType, Type valueType, MapType outputType) {
    DynamicClassLoader classLoader = new DynamicClassLoader(MapUnionSumAggregation.class.getClassLoader());
    List<Type> inputTypes = ImmutableList.of(outputType);
    MapUnionSumStateSerializer stateSerializer = new MapUnionSumStateSerializer(outputType);
    Type intermediateType = stateSerializer.getSerializedType();
    AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, outputType.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(outputType), INPUT_FUNCTION.bindTo(keyType).bindTo(valueType), COMBINE_FUNCTION, OUTPUT_FUNCTION, ImmutableList.of(new AccumulatorStateDescriptor(MapUnionSumState.class, stateSerializer, new MapUnionSumStateFactory(keyType, valueType))), outputType);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), outputType, true, false, factory);
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) MapType(com.facebook.presto.common.type.MapType) Type(com.facebook.presto.common.type.Type) MapUnionSumStateFactory(com.facebook.presto.operator.aggregation.state.MapUnionSumStateFactory) MapUnionSumStateSerializer(com.facebook.presto.operator.aggregation.state.MapUnionSumStateSerializer) AccumulatorStateDescriptor(com.facebook.presto.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor)

Aggregations

MapType (com.facebook.presto.common.type.MapType)2 MapUnionSumStateFactory (com.facebook.presto.operator.aggregation.state.MapUnionSumStateFactory)2 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 DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)1 Block (com.facebook.presto.common.block.Block)1 MapBlock (com.facebook.presto.common.block.MapBlock)1 Type (com.facebook.presto.common.type.Type)1 AccumulatorStateDescriptor (com.facebook.presto.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor)1 MapUnionSumState (com.facebook.presto.operator.aggregation.state.MapUnionSumState)1 MapUnionSumStateSerializer (com.facebook.presto.operator.aggregation.state.MapUnionSumStateSerializer)1 HashMap (java.util.HashMap)1 Test (org.testng.annotations.Test)1