use of com.facebook.presto.operator.aggregation.state.ReduceAggregationStateSerializer in project presto by prestodb.
the class ReduceAggregationFunction method generateAggregation.
private InternalAggregationFunction generateAggregation(Type inputType, Type stateType) {
DynamicClassLoader classLoader = new DynamicClassLoader(ReduceAggregationFunction.class.getClassLoader());
MethodHandle inputMethodHandle;
MethodHandle combineMethodHandle;
MethodHandle outputMethodHandle;
AccumulatorStateDescriptor stateDescriptor;
if (!supportsComplexTypes && !(stateType.getJavaType() == long.class || stateType.getJavaType() == double.class || stateType.getJavaType() == boolean.class)) {
// See JDK-8017163.
throw new PrestoException(NOT_SUPPORTED, format("State type not enabled for %s: %s", NAME, stateType.getDisplayName()));
}
inputMethodHandle = INPUT_FUNCTION.bindTo(inputType);
combineMethodHandle = COMBINE_FUNCTION;
outputMethodHandle = OUTPUT_FUNCTION.bindTo(stateType);
stateDescriptor = new AccumulatorStateDescriptor(ReduceAggregationState.class, new ReduceAggregationStateSerializer(stateType), new ReduceAggregationStateFactory());
AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(getSignature().getNameSuffix(), inputType.getTypeSignature(), ImmutableList.of(inputType.getTypeSignature())), createInputParameterMetadata(inputType, stateType), inputMethodHandle.asType(inputMethodHandle.type().changeParameterType(1, inputType.getJavaType()).changeParameterType(2, stateType.getJavaType())), combineMethodHandle, outputMethodHandle, ImmutableList.of(stateDescriptor), stateType, ImmutableList.of(BinaryFunctionInterface.class, BinaryFunctionInterface.class));
GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
return new InternalAggregationFunction(getSignature().getNameSuffix(), ImmutableList.of(inputType), ImmutableList.of(stateType), stateType, true, false, factory, ImmutableList.of(BinaryFunctionInterface.class, BinaryFunctionInterface.class));
}
Aggregations