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


##########
core/src/test/java/org/apache/calcite/test/UdfTest.java:
##########
@@ -666,6 +679,58 @@ private CalciteAssert.AssertThat withUdf() {
         .returns("EXPR$0={a: 1, b: null, c: 3, d: null, e: null}\n");
   }
 
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-6018";>[CALCITE-6018]
+   * Support nullable parameters in UDFs</a>.
+   *
+   * <p>Tests that {@code @Parameter(nullable = false)} makes a reference type
+   * parameter non-nullable. */
+  @Test void testNonNullParameter() throws Exception {
+    final CalciteAssert.AssertThat with = withUdf();
+    // Non-null parameter accepts non-null value
+    with.query("values \"adhoc\".my_nonnull_param('hello')")
+        .returns("EXPR$0=hello\n");
+
+    // Verify that the parameter type is non-nullable
+    Method method = Smalls.MyNonNullParamFunction.class.getMethod("eval", 
String.class);
+    ScalarFunction func = ScalarFunctionImpl.create(method);
+    List<FunctionParameter> params = func.getParameters();
+    assertThat(params, hasSize(1));
+    org.apache.calcite.rel.type.RelDataTypeFactory typeFactory =
+        new org.apache.calcite.jdbc.JavaTypeFactoryImpl();
+    RelDataType paramType = params.get(0).getType(typeFactory);
+    assertThat("Parameter with @Parameter(nullable=false) should be 
non-nullable",
+        paramType.isNullable(), is(false));
+  }
+
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-6018";>[CALCITE-6018]
+   * Support nullable parameters in UDFs</a>.
+   *
+   * <p>Tests that {@code @Nullable} annotation on a parameter makes it
+   * explicitly nullable, and the function can handle null input. */
+  @Test void testNullableParameter() throws Exception {

Review Comment:
   done as suggested.



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