Search in sources :

Example 1 with ReduceAggregationStateFactory

use of com.facebook.presto.operator.aggregation.state.ReduceAggregationStateFactory 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));
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) ReduceAggregationState(com.facebook.presto.operator.aggregation.state.ReduceAggregationState) ReduceAggregationStateSerializer(com.facebook.presto.operator.aggregation.state.ReduceAggregationStateSerializer) AccumulatorStateDescriptor(com.facebook.presto.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) BinaryFunctionInterface(com.facebook.presto.sql.gen.lambda.BinaryFunctionInterface) PrestoException(com.facebook.presto.spi.PrestoException) MethodHandle(java.lang.invoke.MethodHandle) ReduceAggregationStateFactory(com.facebook.presto.operator.aggregation.state.ReduceAggregationStateFactory)

Aggregations

DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)1 AccumulatorStateDescriptor (com.facebook.presto.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor)1 ReduceAggregationState (com.facebook.presto.operator.aggregation.state.ReduceAggregationState)1 ReduceAggregationStateFactory (com.facebook.presto.operator.aggregation.state.ReduceAggregationStateFactory)1 ReduceAggregationStateSerializer (com.facebook.presto.operator.aggregation.state.ReduceAggregationStateSerializer)1 PrestoException (com.facebook.presto.spi.PrestoException)1 BinaryFunctionInterface (com.facebook.presto.sql.gen.lambda.BinaryFunctionInterface)1 MethodHandle (java.lang.invoke.MethodHandle)1