use of com.facebook.presto.operator.aggregation.InternalAggregationFunction in project presto by prestodb.
the class TestMinMaxByAggregation method testMinLongArrayLong.
@Test
public void testMinLongArrayLong() {
InternalAggregationFunction function = getMinByAggregation(BIGINT, new ArrayType(BIGINT));
assertAggregation(function, 3L, createLongsBlock(1L, 2L, 2L, 3L), createArrayBigintBlock(ImmutableList.of(ImmutableList.of(8L, 9L), ImmutableList.of(1L, 2L), ImmutableList.of(6L, 7L), ImmutableList.of(1L, 1L))));
assertAggregation(function, -1L, createLongsBlock(0L, 1L, 2L, -1L), createArrayBigintBlock(ImmutableList.of(ImmutableList.of(8L, 9L), ImmutableList.of(6L, 7L), ImmutableList.of(-1L, -3L), ImmutableList.of(-1L))));
}
use of com.facebook.presto.operator.aggregation.InternalAggregationFunction in project presto by prestodb.
the class CountAggregationBenchmark method createOperatorFactories.
@Override
protected List<? extends OperatorFactory> createOperatorFactories() {
OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "orderkey");
FunctionAndTypeManager functionAndTypeManager = localQueryRunner.getMetadata().getFunctionAndTypeManager();
InternalAggregationFunction countFunction = functionAndTypeManager.getAggregateFunctionImplementation(functionAndTypeManager.lookupFunction("count", fromTypes(BIGINT)));
AggregationOperatorFactory aggregationOperator = new AggregationOperatorFactory(1, new PlanNodeId("test"), Step.SINGLE, ImmutableList.of(countFunction.bind(ImmutableList.of(0), Optional.empty())), false);
return ImmutableList.of(tableScanOperator, aggregationOperator);
}
use of com.facebook.presto.operator.aggregation.InternalAggregationFunction in project presto by prestodb.
the class MultimapAggregationFunction method generateAggregation.
private InternalAggregationFunction generateAggregation(Type keyType, Type valueType, Type outputType) {
DynamicClassLoader classLoader = new DynamicClassLoader(MultimapAggregationFunction.class.getClassLoader());
List<Type> inputTypes = ImmutableList.of(keyType, valueType);
MultimapAggregationStateSerializer stateSerializer = new MultimapAggregationStateSerializer(keyType, valueType);
Type intermediateType = stateSerializer.getSerializedType();
AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, outputType.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(keyType, valueType), INPUT_FUNCTION, COMBINE_FUNCTION, OUTPUT_FUNCTION.bindTo(keyType).bindTo(valueType), ImmutableList.of(new AccumulatorStateDescriptor(MultimapAggregationState.class, stateSerializer, new MultimapAggregationStateFactory(keyType, valueType, groupMode))), outputType);
GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), outputType, true, true, factory);
}
use of com.facebook.presto.operator.aggregation.InternalAggregationFunction in project presto by prestodb.
the class StatisticAggregations method split.
private Parts split(PlanVariableAllocator variableAllocator, FunctionAndTypeManager functionAndTypeManager, boolean intermediate) {
ImmutableMap.Builder<VariableReferenceExpression, Aggregation> finalOrIntermediateAggregations = ImmutableMap.builder();
ImmutableMap.Builder<VariableReferenceExpression, Aggregation> partialAggregations = ImmutableMap.builder();
for (Map.Entry<VariableReferenceExpression, Aggregation> entry : aggregations.entrySet()) {
Aggregation originalAggregation = entry.getValue();
FunctionHandle functionHandle = originalAggregation.getFunctionHandle();
InternalAggregationFunction function = functionAndTypeManager.getAggregateFunctionImplementation(functionHandle);
// create partial aggregation
VariableReferenceExpression partialVariable = variableAllocator.newVariable(entry.getValue().getCall().getSourceLocation(), functionAndTypeManager.getFunctionMetadata(functionHandle).getName().getObjectName(), function.getIntermediateType());
partialAggregations.put(partialVariable, new Aggregation(new CallExpression(originalAggregation.getCall().getSourceLocation(), originalAggregation.getCall().getDisplayName(), functionHandle, function.getIntermediateType(), originalAggregation.getArguments()), originalAggregation.getFilter(), originalAggregation.getOrderBy(), originalAggregation.isDistinct(), originalAggregation.getMask()));
// create final aggregation
finalOrIntermediateAggregations.put(entry.getKey(), new Aggregation(new CallExpression(originalAggregation.getCall().getSourceLocation(), originalAggregation.getCall().getDisplayName(), functionHandle, intermediate ? function.getIntermediateType() : function.getFinalType(), ImmutableList.of(partialVariable)), Optional.empty(), Optional.empty(), false, Optional.empty()));
}
StatisticAggregations finalOrIntermediateAggregation = new StatisticAggregations(finalOrIntermediateAggregations.build(), groupingVariables);
return new Parts(intermediate ? Optional.empty() : Optional.of(finalOrIntermediateAggregation), intermediate ? Optional.of(finalOrIntermediateAggregation) : Optional.empty(), new StatisticAggregations(partialAggregations.build(), groupingVariables));
}
use of com.facebook.presto.operator.aggregation.InternalAggregationFunction in project presto by prestodb.
the class TestMinMaxByAggregation method testMaxSliceLongArray.
@Test
public void testMaxSliceLongArray() {
InternalAggregationFunction function = getMaxByAggregation(new ArrayType(BIGINT), VARCHAR);
assertAggregation(function, asList(2L, 2L), createArrayBigintBlock(asList(asList(3L, 4L), null, asList(2L, 2L))), createStringsBlock("a", "b", "c"));
assertAggregation(function, null, createArrayBigintBlock(asList(asList(3L, 4L), null, null)), createStringsBlock("a", "b", "c"));
}
Aggregations