Search in sources :

Example 1 with SetAggregationStateFactory

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

the class SetUnionFunction method specialize.

@Override
public InternalAggregationFunction specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager) {
    Type elementType = boundVariables.getTypeVariable("T");
    ArrayType arrayType = (ArrayType) functionAndTypeManager.getParameterizedType(StandardTypes.ARRAY, ImmutableList.of(TypeSignatureParameter.of(elementType.getTypeSignature())));
    DynamicClassLoader classLoader = new DynamicClassLoader(SetUnionFunction.class.getClassLoader());
    AccumulatorStateSerializer<?> stateSerializer = new SetAggregationStateSerializer(arrayType);
    AccumulatorStateFactory<?> stateFactory = new SetAggregationStateFactory(elementType);
    Class<? extends AccumulatorState> stateInterface = SetAggregationState.class;
    List<ParameterMetadata> inputParameterMetadata = ImmutableList.of(new ParameterMetadata(STATE), new ParameterMetadata(NULLABLE_BLOCK_INPUT_CHANNEL, elementType), new ParameterMetadata(BLOCK_INDEX));
    AggregationMetadata metadata = new AggregationMetadata(AggregationUtils.generateAggregationName(NAME, arrayType.getTypeSignature(), ImmutableList.of(elementType.getTypeSignature())), inputParameterMetadata, INPUT_FUNCTION.bindTo(elementType).bindTo(arrayType), COMBINE_FUNCTION, OUTPUT_FUNCTION, ImmutableList.of(new AccumulatorStateDescriptor(stateInterface, stateSerializer, stateFactory)), arrayType);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(NAME, ImmutableList.of(elementType), ImmutableList.of(stateSerializer.getSerializedType()), arrayType, true, true, factory);
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) SetAggregationStateFactory(com.facebook.presto.operator.aggregation.state.SetAggregationStateFactory) AccumulatorStateDescriptor(com.facebook.presto.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) GenericAccumulatorFactoryBinder(com.facebook.presto.operator.aggregation.GenericAccumulatorFactoryBinder) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) ParameterMetadata(com.facebook.presto.operator.aggregation.AggregationMetadata.ParameterMetadata) ArrayType(com.facebook.presto.common.type.ArrayType) ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) SetAggregationState(com.facebook.presto.operator.aggregation.state.SetAggregationState) AggregationMetadata(com.facebook.presto.operator.aggregation.AggregationMetadata)

Example 2 with SetAggregationStateFactory

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

the class SetAggregationFunction method generateAggregation.

private static InternalAggregationFunction generateAggregation(Type type, ArrayType outputType) {
    DynamicClassLoader classLoader = new DynamicClassLoader(SetAggregationFunction.class.getClassLoader());
    List<Type> inputTypes = ImmutableList.of(type);
    AccumulatorStateSerializer<?> stateSerializer = new SetAggregationStateSerializer(outputType);
    AccumulatorStateFactory<?> stateFactory = new SetAggregationStateFactory(type);
    Type intermediateType = stateSerializer.getSerializedType();
    List<ParameterMetadata> inputParameterMetadata = createInputParameterMetadata(type);
    Class<? extends AccumulatorState> stateInterface = SetAggregationState.class;
    AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, outputType.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), inputParameterMetadata, INPUT_FUNCTION.bindTo(type), COMBINE_FUNCTION, OUTPUT_FUNCTION, ImmutableList.of(new AccumulatorStateDescriptor(stateInterface, stateSerializer, stateFactory)), outputType);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), outputType, true, true, factory);
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) SetAggregationStateFactory(com.facebook.presto.operator.aggregation.state.SetAggregationStateFactory) AccumulatorStateDescriptor(com.facebook.presto.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) GenericAccumulatorFactoryBinder(com.facebook.presto.operator.aggregation.GenericAccumulatorFactoryBinder) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) ParameterMetadata(com.facebook.presto.operator.aggregation.AggregationMetadata.ParameterMetadata) ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) SetAggregationState(com.facebook.presto.operator.aggregation.state.SetAggregationState) AggregationMetadata(com.facebook.presto.operator.aggregation.AggregationMetadata)

Aggregations

DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)2 ArrayType (com.facebook.presto.common.type.ArrayType)2 Type (com.facebook.presto.common.type.Type)2 AggregationMetadata (com.facebook.presto.operator.aggregation.AggregationMetadata)2 AccumulatorStateDescriptor (com.facebook.presto.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor)2 ParameterMetadata (com.facebook.presto.operator.aggregation.AggregationMetadata.ParameterMetadata)2 GenericAccumulatorFactoryBinder (com.facebook.presto.operator.aggregation.GenericAccumulatorFactoryBinder)2 InternalAggregationFunction (com.facebook.presto.operator.aggregation.InternalAggregationFunction)2 SetAggregationState (com.facebook.presto.operator.aggregation.state.SetAggregationState)2 SetAggregationStateFactory (com.facebook.presto.operator.aggregation.state.SetAggregationStateFactory)2