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());
}
Aggregations