Search in sources :

Example 1 with MethodAndNativeContainerTypes

use of io.trino.metadata.PolymorphicScalarFunctionBuilder.MethodAndNativeContainerTypes in project trino by trinodb.

the class PolymorphicScalarFunction method getScalarFunctionImplementationChoice.

private ScalarImplementationChoice getScalarFunctionImplementationChoice(FunctionBinding functionBinding, PolymorphicScalarFunctionChoice choice) {
    SpecializeContext context = new SpecializeContext(functionBinding);
    Optional<MethodAndNativeContainerTypes> matchingMethod = Optional.empty();
    Optional<MethodsGroup> matchingMethodsGroup = Optional.empty();
    for (MethodsGroup candidateMethodsGroup : choice.getMethodsGroups()) {
        for (MethodAndNativeContainerTypes candidateMethod : candidateMethodsGroup.getMethods()) {
            if (matchesParameterAndReturnTypes(candidateMethod, functionBinding.getBoundSignature(), choice.getArgumentConventions(), choice.getReturnConvention())) {
                if (matchingMethod.isPresent()) {
                    throw new IllegalStateException("two matching methods (" + matchingMethod.get().getMethod().getName() + " and " + candidateMethod.getMethod().getName() + ") for parameter types " + functionBinding.getBoundSignature().getArgumentTypes());
                }
                matchingMethod = Optional.of(candidateMethod);
                matchingMethodsGroup = Optional.of(candidateMethodsGroup);
            }
        }
    }
    checkState(matchingMethod.isPresent(), "no matching method for parameter types %s", functionBinding.getBoundSignature());
    List<Object> extraParameters = computeExtraParameters(matchingMethodsGroup.get(), context);
    MethodHandle methodHandle = applyExtraParameters(matchingMethod.get().getMethod(), extraParameters, choice.getArgumentConventions());
    return new ScalarImplementationChoice(choice.getReturnConvention(), choice.getArgumentConventions(), ImmutableList.of(), methodHandle, Optional.empty());
}
Also used : SpecializeContext(io.trino.metadata.PolymorphicScalarFunctionBuilder.SpecializeContext) MethodAndNativeContainerTypes(io.trino.metadata.PolymorphicScalarFunctionBuilder.MethodAndNativeContainerTypes) MethodsGroup(io.trino.metadata.PolymorphicScalarFunctionBuilder.MethodsGroup) ScalarImplementationChoice(io.trino.operator.scalar.ChoicesScalarFunctionImplementation.ScalarImplementationChoice) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

MethodAndNativeContainerTypes (io.trino.metadata.PolymorphicScalarFunctionBuilder.MethodAndNativeContainerTypes)1 MethodsGroup (io.trino.metadata.PolymorphicScalarFunctionBuilder.MethodsGroup)1 SpecializeContext (io.trino.metadata.PolymorphicScalarFunctionBuilder.SpecializeContext)1 ScalarImplementationChoice (io.trino.operator.scalar.ChoicesScalarFunctionImplementation.ScalarImplementationChoice)1 MethodHandle (java.lang.invoke.MethodHandle)1