xuzifu666 commented on code in PR #5386:
URL: https://github.com/apache/calcite/pull/5386#discussion_r4481492140


##########
core/src/main/java/org/apache/calcite/util/ReflectUtil.java:
##########
@@ -590,6 +590,37 @@ public static boolean isParameterOptional(Method method, 
int i) {
     return false;
   }
 
+  /** Derives whether the {@code i}th parameter of a method is nullable.
+   *
+   * <p>The algorithm is as follows:
+   * <ul>
+   *   <li>If the parameter has a {@code @Nullable} annotation (from any
+   *       well-known nullness library such as jspecify, Checker Framework,
+   *       or javax.annotation), returns true.</li>
+   *   <li>If the parameter has a {@link Parameter} annotation with
+   *       {@code nullable = false}, returns false.</li>
+   *   <li>Otherwise, returns whether the Java type is not a primitive
+   *       (i.e., the default nullability derived from the type).</li>
+   * </ul>
+   */
+  public static boolean isParameterNullable(Method method, int i) {
+    final Annotation[] annotations = method.getParameterAnnotations()[i];
+    // Check for @Nullable annotation from any well-known library
+    for (Annotation annotation : annotations) {
+      if (annotation.annotationType().getSimpleName().equals("Nullable")) {
+        return true;
+      }
+    }
+    // Check @Parameter annotation for explicit nullable attribute
+    for (Annotation annotation : annotations) {
+      if (annotation.annotationType() == Parameter.class) {
+        return ((Parameter) annotation).nullable();

Review Comment:
   I settled on the second option: the change only affects the parameter type 
reported through FunctionParameter.getType(RelDataTypeFactory). The validator 
does not reject a call that passes NULL to a parameter whose type is NOT NULL — 
the call is accepted and returns NULL. This is stated in the 
isParameterNullable javadoc and the PR description, and covered by a new test 
asserting values "adhoc".my_nonnull_param(cast(null as varchar)) returns NULL.



-- 
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]

Reply via email to