Search in sources :

Example 1 with TypeSignature.parseTypeSignature

use of com.facebook.presto.spi.type.TypeSignature.parseTypeSignature in project presto by prestodb.

the class AggregationCompiler method generateBindableAggregationFunctions.

public static List<BindableAggregationFunction> generateBindableAggregationFunctions(Class<?> aggregationDefinition) {
    AggregationFunction aggregationAnnotation = aggregationDefinition.getAnnotation(AggregationFunction.class);
    requireNonNull(aggregationAnnotation, "aggregationAnnotation is null");
    DynamicClassLoader classLoader = new DynamicClassLoader(aggregationDefinition.getClassLoader());
    ImmutableList.Builder<BindableAggregationFunction> builder = ImmutableList.builder();
    for (Class<?> stateClass : getStateClasses(aggregationDefinition)) {
        AccumulatorStateSerializer<?> stateSerializer = StateCompiler.generateStateSerializer(stateClass, classLoader);
        for (Method outputFunction : getOutputFunctions(aggregationDefinition, stateClass)) {
            for (Method inputFunction : getInputFunctions(aggregationDefinition, stateClass)) {
                List<LongVariableConstraint> longVariableConstraints = parseLongVariableConstraints(inputFunction);
                for (String name : getNames(outputFunction, aggregationAnnotation)) {
                    List<TypeSignature> inputTypes = getInputTypesSignatures(inputFunction);
                    TypeSignature outputType = TypeSignature.parseTypeSignature(outputFunction.getAnnotation(OutputFunction.class).value());
                    builder.add(new BindableAggregationFunction(new Signature(name, FunctionKind.AGGREGATE, // TODO parse constrains from annotations
                    ImmutableList.of(), longVariableConstraints, outputType, inputTypes, false), getDescription(aggregationDefinition, outputFunction), aggregationAnnotation.decomposable(), aggregationDefinition, stateClass, inputFunction, outputFunction));
                }
            }
        }
    }
    return builder.build();
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) ImmutableList(com.google.common.collect.ImmutableList) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) Method(java.lang.reflect.Method) AggregationFunction(com.facebook.presto.spi.function.AggregationFunction) TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) LongVariableConstraint(com.facebook.presto.metadata.LongVariableConstraint) TypeSignature(com.facebook.presto.spi.type.TypeSignature) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)

Aggregations

DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)1 LongVariableConstraint (com.facebook.presto.metadata.LongVariableConstraint)1 Signature (com.facebook.presto.metadata.Signature)1 AggregationFunction (com.facebook.presto.spi.function.AggregationFunction)1 TypeSignature (com.facebook.presto.spi.type.TypeSignature)1 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)1 ImmutableCollectors.toImmutableList (com.facebook.presto.util.ImmutableCollectors.toImmutableList)1 ImmutableList (com.google.common.collect.ImmutableList)1 Method (java.lang.reflect.Method)1