59 Set<ExtTableFunction> candidateOverloads =
new HashSet<ExtTableFunction>(
62 for (SqlNode operand : callBinding.getCall().getOperandList()) {
63 if (operand != null && operand.getKind() == SqlKind.ARGUMENT_ASSIGNMENT) {
64 final SqlCall assignmentCall = (SqlCall) operand;
65 final SqlIdentifier
id = assignmentCall.operand(1);
66 final String paramName = id.getSimple();
67 if (!candidateOverloads.stream().anyMatch(
68 tf -> tf.getParamNames().
contains(paramName))) {
76 candidateOverloads.removeIf(tf
77 -> (callBinding.getOperandCount()
78 < (tf.getArgTypes().size() - tf.getNumOptionalArguments()))
79 || (callBinding.getOperandCount() > tf.getArgTypes().size()));
81 SqlNode[] operandArray =
new SqlNode[callBinding.getCall().getOperandList().size()];
82 for (Ord<SqlNode> arg : Ord.zip(callBinding.getCall().getOperandList())) {
83 operandArray[arg.i] = arg.e;
89 HashMap<ExtTableFunction, SqlCallBinding> candidateBindings =
90 new HashMap<>(candidateOverloads.size());
91 for (ExtTableFunction tf : candidateOverloads) {
92 SqlBasicCall newCall =
new SqlBasicCall(
93 tf, operandArray, callBinding.getCall().getParserPosition());
94 SqlCallBinding candidateBinding =
new SqlCallBinding(
95 callBinding.getValidator(), callBinding.getScope(), newCall);
96 candidateBindings.put(tf, candidateBinding);
101 candidateOverloads.removeIf(tf
104 candidateBindings.get(tf)
109 -> candidateBindings.get(tf)
114 && !tf.isArgumentOptional(idx)));
117 HeavyDBTypeCoercion tc =
118 (HeavyDBTypeCoercion) callBinding.getValidator().getTypeCoercion();
119 Map<ExtTableFunction, Integer> scoredCandidates =
120 new HashMap<ExtTableFunction, Integer>();
121 candidateOverloads.stream().forEach(udtf
122 -> scoredCandidates.put(udtf,
123 tc.calculateTypeCoercionScore(candidateBindings.get(udtf), udtf)));
126 ExtTableFunction minCandidate;
128 minCandidate = Collections
129 .min(scoredCandidates.entrySet()
131 .filter(entry -> entry.getValue() >= 0)
132 .collect(Collectors.toSet()),
133 Map.Entry.comparingByValue())
135 }
catch (NoSuchElementException e) {
137 if (throwOnFailure) {
143 if (scoredCandidates.get(minCandidate) > 0) {
144 tc.extTableFunctionTypeCoercion(candidateBindings.get(minCandidate), minCandidate);
149 ((SqlBasicCall) callBinding.getCall()).setOperator(minCandidate);
bool contains(const T &container, const U &element)
CalciteException newExtTableFunctionNameError(SqlCallBinding callBinding, SqlNode operand, String operandName)
CalciteException newExtTableFunctionSignatureError(SqlCallBinding callBinding)
List< ExtTableFunction > getOperatorOverloads(SqlOperator op)