liuyongvs commented on code in PR #3207:
URL: https://github.com/apache/calcite/pull/3207#discussion_r1221193438


##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -5364,6 +5364,31 @@ private static void checkIf(SqlOperatorFixture f) {
     f.checkNull("array_concat(cast(null as integer array), array[1])");
   }
 
+  /** Tests {@code ARRAY_CONTAINS} function from Spark. */
+  @Test void testArrayContainsFunc() {
+    final SqlOperatorFixture f0 = fixture();
+    f0.setFor(SqlLibraryOperators.ARRAY_CONTAINS);
+    f0.checkFails("^array_contains(array[1, 2], 1)^",
+        "No match found for function signature "
+            + "ARRAY_CONTAINS\\(<INTEGER ARRAY>, <NUMERIC>\\)", false);
+
+    final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.SPARK);
+    f.checkScalar("array_contains(array[1, 2], 1)", true,
+        "BOOLEAN NOT NULL");
+    f.checkScalar("array_contains(array[1, null], cast(null as integer))", 
true,
+        "BOOLEAN NOT NULL");

Review Comment:
   you should use array_contains(array[1, null], cast(null as integer) 
   and for my side, spark the behavior is not good the second arg is null, also 
return null.
   so i does flink way, in flink array_contains(array[1, null], cast(null as 
integer)  it return true, while in spark return null
   
   public static final BuiltInFunctionDefinition ARRAY_CONTAINS =
               BuiltInFunctionDefinition.newBuilder()
                       .name("ARRAY_CONTAINS")
                       .kind(SCALAR)
                       .inputTypeStrategy(
                               sequence(
                                       Arrays.asList("haystack", "needle"),
                                       Arrays.asList(
                                               logical(LogicalTypeRoot.ARRAY), 
ARRAY_ELEMENT_ARG)))
                       .outputTypeStrategy(
                               nullableIfArgs(
                                       ConstantArgumentCount.of(0), 
explicit(DataTypes.BOOLEAN())))
                       .runtimeClass(
                               
"org.apache.flink.table.runtime.functions.scalar.ArrayContainsFunction")
                       .build();



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