You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "MasseGuillaume (via GitHub)" <gi...@apache.org> on 2023/06/01 03:28:13 UTC

[GitHub] [calcite] MasseGuillaume commented on a diff in pull request #3207: [CALCITE-5707] Add ARRAY_CONTAINS function (enabled in Spark library)

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


##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -5324,6 +5324,27 @@ 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");
+    f.checkScalar("array_contains(array[map[1, 'a'], map[2, 'b']], map[1, 'a'])", true,
+        "BOOLEAN NOT NULL");
+    f.checkFails("^array_contains(array[1, 2], true)^",
+        "INTEGER is not comparable to BOOLEAN", false);
+    f.checkNull("array_contains(cast(null as integer array), 1)");
+    f.checkType("array_contains(cast(null as integer array), 1)", "BOOLEAN");
+  }

Review Comment:
   ```suggestion
         f.checkScalar("array_contains(array[1], 1)", true,
           "BOOLEAN NOT NULL");
         f.checkScalar("array_contains(array(), 1)", false,
           "BOOLEAN NOT 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: commits-unsubscribe@calcite.apache.org

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