Search in sources :

Example 1 with ParametricImplementationsGroup

use of com.facebook.presto.operator.ParametricImplementationsGroup in project presto by prestodb.

the class ScalarFromAnnotationsParser method parseParametricScalar.

private static SqlScalarFunction parseParametricScalar(ScalarHeaderAndMethods scalar, Optional<Constructor<?>> constructor) {
    ScalarImplementationHeader header = scalar.getHeader();
    Map<SpecializedSignature, ParametricScalarImplementation.Builder> signatures = new HashMap<>();
    for (Method method : scalar.getMethods()) {
        ParametricScalarImplementation implementation = ParametricScalarImplementation.Parser.parseImplementation(header, method, constructor);
        if (!signatures.containsKey(implementation.getSpecializedSignature())) {
            ParametricScalarImplementation.Builder builder = new ParametricScalarImplementation.Builder(implementation.getSignature(), implementation.getArgumentNativeContainerTypes(), implementation.getSpecializedTypeParameters(), implementation.getReturnNativeContainerType());
            signatures.put(implementation.getSpecializedSignature(), builder);
            builder.addChoices(implementation);
        } else {
            ParametricScalarImplementation.Builder builder = signatures.get(implementation.getSpecializedSignature());
            builder.addChoices(implementation);
        }
    }
    ParametricImplementationsGroup.Builder<ParametricScalarImplementation> implementationsBuilder = ParametricImplementationsGroup.builder();
    for (ParametricScalarImplementation.Builder implementation : signatures.values()) {
        implementationsBuilder.addImplementation(implementation.build());
    }
    ParametricImplementationsGroup<ParametricScalarImplementation> implementations = implementationsBuilder.build();
    Signature scalarSignature = implementations.getSignature();
    header.getOperatorType().ifPresent(operatorType -> validateOperator(operatorType, scalarSignature.getReturnType(), scalarSignature.getArgumentTypes()));
    return new ParametricScalar(scalarSignature, header.getHeader(), implementations);
}
Also used : SpecializedSignature(com.facebook.presto.operator.scalar.annotations.ParametricScalarImplementation.SpecializedSignature) HashMap(java.util.HashMap) ParametricImplementationsGroup(com.facebook.presto.operator.ParametricImplementationsGroup) Method(java.lang.reflect.Method) SpecializedSignature(com.facebook.presto.operator.scalar.annotations.ParametricScalarImplementation.SpecializedSignature) Signature(com.facebook.presto.spi.function.Signature) ParametricScalar(com.facebook.presto.operator.scalar.ParametricScalar)

Example 2 with ParametricImplementationsGroup

use of com.facebook.presto.operator.ParametricImplementationsGroup in project presto by prestodb.

the class AggregationFromAnnotationsParser method parseFunctionDefinition.

public static ParametricAggregation parseFunctionDefinition(Class<?> aggregationDefinition) {
    ParametricImplementationsGroup.Builder<AggregationImplementation> implementationsBuilder = ParametricImplementationsGroup.builder();
    AggregationHeader header = parseHeader(aggregationDefinition);
    for (Class<?> stateClass : getStateClasses(aggregationDefinition)) {
        Method combineFunction = getCombineFunction(aggregationDefinition, stateClass);
        Optional<Method> aggregationStateSerializerFactory = getAggregationStateSerializerFactory(aggregationDefinition, stateClass);
        Method outputFunction = getOnlyElement(getOutputFunctions(aggregationDefinition, stateClass));
        for (Method inputFunction : getInputFunctions(aggregationDefinition, stateClass)) {
            AggregationImplementation implementation = parseImplementation(aggregationDefinition, header, stateClass, inputFunction, outputFunction, combineFunction, aggregationStateSerializerFactory);
            implementationsBuilder.addImplementation(implementation);
        }
    }
    ParametricImplementationsGroup<AggregationImplementation> implementations = implementationsBuilder.build();
    return new ParametricAggregation(implementations.getSignature(), header, implementations);
}
Also used : ParametricImplementationsGroup(com.facebook.presto.operator.ParametricImplementationsGroup) Method(java.lang.reflect.Method)

Aggregations

ParametricImplementationsGroup (com.facebook.presto.operator.ParametricImplementationsGroup)2 Method (java.lang.reflect.Method)2 ParametricScalar (com.facebook.presto.operator.scalar.ParametricScalar)1 SpecializedSignature (com.facebook.presto.operator.scalar.annotations.ParametricScalarImplementation.SpecializedSignature)1 Signature (com.facebook.presto.spi.function.Signature)1 HashMap (java.util.HashMap)1