Search in sources :

Example 1 with MethodsGroup

use of io.prestosql.metadata.PolymorphicScalarFunctionBuilder.MethodsGroup in project hetu-core by openlookeng.

the class PolymorphicScalarFunction method getScalarFunctionImplementationChoice.

private ScalarImplementationChoice getScalarFunctionImplementationChoice(BoundVariables boundVariables, FunctionAndTypeManager functionAndTypeManager, PolymorphicScalarFunctionChoice choice) {
    List<Type> resolvedParameterTypes = applyBoundVariables(functionAndTypeManager, getSignature().getArgumentTypes(), boundVariables);
    Type resolvedReturnType = applyBoundVariables(functionAndTypeManager, getSignature().getReturnType(), boundVariables);
    SpecializeContext context = new SpecializeContext(boundVariables, resolvedParameterTypes, resolvedReturnType, functionAndTypeManager);
    Optional<MethodAndNativeContainerTypes> matchingMethod = Optional.empty();
    Optional<MethodsGroup> matchingMethodsGroup = Optional.empty();
    for (MethodsGroup candidateMethodsGroup : choice.getMethodsGroups()) {
        for (MethodAndNativeContainerTypes candidateMethod : candidateMethodsGroup.getMethods()) {
            if (matchesParameterAndReturnTypes(candidateMethod, resolvedParameterTypes, resolvedReturnType, choice.getArgumentProperties(), choice.isNullableResult())) {
                if (matchingMethod.isPresent()) {
                    throw new IllegalStateException("two matching methods (" + matchingMethod.get().getMethod().getName() + " and " + candidateMethod.getMethod().getName() + ") for parameter types " + resolvedParameterTypes);
                }
                matchingMethod = Optional.of(candidateMethod);
                matchingMethodsGroup = Optional.of(candidateMethodsGroup);
            }
        }
    }
    checkState(matchingMethod.isPresent(), "no matching method for parameter types %s", resolvedParameterTypes);
    List<Object> extraParameters = computeExtraParameters(matchingMethodsGroup.get(), context);
    MethodHandle methodHandle = applyExtraParameters(matchingMethod.get().getMethod(), extraParameters, choice.getArgumentProperties());
    return new ScalarImplementationChoice(choice.isNullableResult(), choice.getArgumentProperties(), choice.getReturnPlaceConvention(), methodHandle, Optional.empty());
}
Also used : SpecializeContext(io.prestosql.metadata.PolymorphicScalarFunctionBuilder.SpecializeContext) Type(io.prestosql.spi.type.Type) MethodAndNativeContainerTypes(io.prestosql.metadata.PolymorphicScalarFunctionBuilder.MethodAndNativeContainerTypes) MethodsGroup(io.prestosql.metadata.PolymorphicScalarFunctionBuilder.MethodsGroup) ScalarImplementationChoice(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ScalarImplementationChoice) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

MethodAndNativeContainerTypes (io.prestosql.metadata.PolymorphicScalarFunctionBuilder.MethodAndNativeContainerTypes)1 MethodsGroup (io.prestosql.metadata.PolymorphicScalarFunctionBuilder.MethodsGroup)1 SpecializeContext (io.prestosql.metadata.PolymorphicScalarFunctionBuilder.SpecializeContext)1 ScalarImplementationChoice (io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ScalarImplementationChoice)1 Type (io.prestosql.spi.type.Type)1 MethodHandle (java.lang.invoke.MethodHandle)1