Search in sources :

Example 1 with SpecializedSignature

use of io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.SpecializedSignature in project hetu-core by openlookeng.

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(io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.SpecializedSignature) HashMap(java.util.HashMap) ParametricImplementationsGroup(io.prestosql.operator.ParametricImplementationsGroup) Method(java.lang.reflect.Method) SpecializedSignature(io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.SpecializedSignature) Signature(io.prestosql.spi.function.Signature) ParametricScalar(io.prestosql.operator.scalar.ParametricScalar)

Aggregations

ParametricImplementationsGroup (io.prestosql.operator.ParametricImplementationsGroup)1 ParametricScalar (io.prestosql.operator.scalar.ParametricScalar)1 SpecializedSignature (io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.SpecializedSignature)1 Signature (io.prestosql.spi.function.Signature)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1