davidradl commented on code in PR #26282:
URL: https://github.com/apache/flink/pull/26282#discussion_r1989637015


##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/expressions/resolver/rules/ResolveCallByArgumentsRule.java:
##########
@@ -247,6 +265,85 @@ private Optional<TypeInference> 
getOptionalTypeInference(FunctionDefinition defi
             }
         }
 
+        private UnresolvedCallExpression executeAssignment(
+                String functionName,
+                TypeInference inference,
+                UnresolvedCallExpression unresolvedCall) {
+            final List<Expression> actualArgs = unresolvedCall.getChildren();
+            final Map<String, Expression> namedArgs = new HashMap<>();
+
+            actualArgs.stream()
+                    .map(this::extractAssignment)
+                    .filter(Objects::nonNull)
+                    .forEach(
+                            assignment -> {
+                                if 
(namedArgs.containsKey(assignment.getKey())) {
+                                    throw new ValidationException(
+                                            String.format(
+                                                    "Invalid call to function 
'%s'. "
+                                                            + "Duplicate named 
argument found: %s",
+                                                    functionName, 
assignment.getKey()));
+                                }
+                                namedArgs.put(assignment.getKey(), 
assignment.getValue());
+                            });
+
+            if (namedArgs.isEmpty()) {
+                // Use position-based call
+                return unresolvedCall;
+            }
+
+            final List<StaticArgument> declaredArgs = 
inference.getStaticArguments().orElse(null);
+            if (declaredArgs == null) {
+                throw new ValidationException(
+                        String.format(
+                                "Invalid call to function '%s'. "
+                                        + "The function does not support named 
arguments. "
+                                        + "Please pass the arguments based on 
positions (i.e. without asArgument()).",
+                                functionName));
+            }
+
+            // Fill optional arguments
+            declaredArgs.forEach(
+                    declaredArg -> {
+                        if (declaredArg.isOptional()) {
+                            namedArgs.putIfAbsent(
+                                    declaredArg.getName(), valueLiteral(null, 
DataTypes.NULL()));

Review Comment:
   Could an optional argument have a default? Or is this handled elsewhere? 



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to