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