zzwqqq commented on code in PR #4794:
URL: https://github.com/apache/calcite/pull/4794#discussion_r2807473893
##########
core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java:
##########
@@ -171,14 +172,57 @@ private Collection<org.apache.calcite.schema.Function>
getFunctionsFrom(
SqlValidatorUtil.getSchema(rootSchema,
Iterables.concat(schemaNames, Util.skipLast(names)),
nameMatcher);
if (schema != null) {
- final String name = Util.last(names);
- boolean caseSensitive = nameMatcher.isCaseSensitive();
- functions2.addAll(schema.getFunctions(name, caseSensitive));
+ final String functionName = Util.last(names);
+ if (nameMatcher.isCaseSensitive()) {
+ addFunctions(functions2, schema, names, functionName, true);
+ } else {
+ boolean hasMatchedFunctionName = false;
+ for (String candidateFunctionName : schema.getFunctionNames()) {
+ if (nameMatcher.matches(functionName, candidateFunctionName)) {
+ hasMatchedFunctionName = true;
+ // candidateFunctionName already has canonical case from schema.
+ // Use case-sensitive lookup to bind each function to that exact
name.
+ addFunctions(functions2, schema, names, candidateFunctionName,
true);
+ }
+ }
+ if (!hasMatchedFunctionName) {
+ // Fallback for schemas where getFunctionNames() is incomplete but
+ // getFunctions(name, false) can still resolve functions.
+ addFunctions(functions2, schema, names, functionName, false);
+ }
+ }
}
}
return functions2;
}
+ private static SqlIdentifier resolvedFunctionIdentifier(CalciteSchema schema,
+ List<String> names, String functionName) {
+ final List<String> schemaPath = schema.path(null);
+ // Keep the same qualifier depth as the original call (e.g. schema.func
+ // stays 2-part, catalog.schema.func stays 3-part).
+ final int qualifierCount = names.size() - 1;
+ // Replace only the suffix that corresponds to the resolved schema path.
+ // Any leading qualifiers that are outside this schema path are kept as-is.
+ final int resolvedQualifierCount = Math.min(qualifierCount,
schemaPath.size());
+ final List<String> resolvedNames = new ArrayList<>(names.size());
+ resolvedNames.addAll(names.subList(0, qualifierCount -
resolvedQualifierCount));
+ resolvedNames.addAll(
+ schemaPath.subList(schemaPath.size() - resolvedQualifierCount,
schemaPath.size()));
+ resolvedNames.add(functionName);
+ return new SqlIdentifier(resolvedNames, SqlParserPos.ZERO);
Review Comment:
Thanks for catching this.
I have updated to keep the original identifier position
(`opName.getParserPosition()`) when creating the resolved identifier, instead
of using `SqlParserPos.ZERO`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]