danny0405 commented on a change in pull request #1405: [CALCITE-2772] Support
varargs UDF for scalar function
URL: https://github.com/apache/calcite/pull/1405#discussion_r317865214
##########
File path: core/src/main/java/org/apache/calcite/sql/SqlUtil.java
##########
@@ -581,47 +581,66 @@ public static boolean matchRoutinesByParameterCount(
return (Iterator) Iterators.filter(
Iterators.filter(routines, SqlFunction.class),
function -> {
- List<RelDataType> paramTypes =
+ final List<RelDataType> paramTypes =
Objects.requireNonNull(function).getParamTypes();
+
if (paramTypes == null) {
// no parameter information for builtins; keep for now
return true;
}
+
+ // convert to mutable list.
+ List<RelDataType> permutedParamTypes =
Lists.newArrayList(paramTypes);
+
final List<RelDataType> permutedArgTypes;
- if (argNames != null) {
- // Arguments passed by name. Make sure that the function has
- // parameters of all of these names.
- final Map<Integer, Integer> map = new HashMap<>();
- for (Ord<String> argName : Ord.zip(argNames)) {
- final int i = function.getParamNames().indexOf(argName.e);
- if (i < 0) {
- return false;
+ boolean varArgs = function.isVarArgs();
+
+ if (!varArgs) {
+ if (argNames != null) {
+ // Arguments passed by name. Make sure that the function has
+ // parameters of all of these names.
+ final Map<Integer, Integer> map = new HashMap<>();
+ for (Ord<String> argName : Ord.zip(argNames)) {
+ final int i = function.getParamNames().indexOf(argName.e);
+ if (i < 0) {
+ return false;
+ }
+ map.put(i, argName.i);
}
- map.put(i, argName.i);
+ permutedArgTypes = Functions.generate(paramTypes.size(), a0 -> {
+ if (map.containsKey(a0)) {
+ return argTypes.get(map.get(a0));
+ } else {
+ return null;
+ }
+ });
+ } else {
+ permutedArgTypes = Lists.newArrayList(argTypes);
Review comment:
Even though the parameters is length varying, we can still do the name check.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services