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/04/18 17:53:44 UTC

[GitHub] [calcite] MasseGuillaume commented on a diff in pull request #3161: [CALCITE-5657] Add ARRAY_DISTINCT function (enabled in Spark library).

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


##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -5167,6 +5167,18 @@ private static void checkIf(SqlOperatorFixture f) {
     f.checkNull("array_concat(cast(null as integer array), array[1])");
   }
 
+  /** Tests {@code ARRAY_DISTINCT} function from Spark. */
+  @Test void testArrayDistinctFunc() {
+    SqlOperatorFixture f = fixture()
+        .setFor(SqlLibraryOperators.ARRAY_DISTINCT)
+        .withLibrary(SqlLibrary.SPARK);
+    f.checkScalar("array_distinct(array[1, 2, 2, 1])", "[1, 2]",
+        "INTEGER NOT NULL ARRAY NOT NULL");
+    f.checkScalar("array_distinct(array[null, 1, null])", "[null, 1]",
+        "INTEGER ARRAY NOT NULL");
+    f.checkNull("array_distinct(null)");
+  }

Review Comment:
   once we have https://github.com/apache/calcite/pull/3141 merged, you will be able to check type for empty:
   
   ```scala
   spark.sql("SELECT array_distinct(array())")
   res3: org.apache.spark.sql.DataFrame = [array_distinct(array()): array<void>]
   ```
   
   



##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -5167,6 +5167,18 @@ private static void checkIf(SqlOperatorFixture f) {
     f.checkNull("array_concat(cast(null as integer array), array[1])");
   }
 
+  /** Tests {@code ARRAY_DISTINCT} function from Spark. */
+  @Test void testArrayDistinctFunc() {
+    SqlOperatorFixture f = fixture()
+        .setFor(SqlLibraryOperators.ARRAY_DISTINCT)
+        .withLibrary(SqlLibrary.SPARK);
+    f.checkScalar("array_distinct(array[1, 2, 2, 1])", "[1, 2]",
+        "INTEGER NOT NULL ARRAY NOT NULL");
+    f.checkScalar("array_distinct(array[null, 1, null])", "[null, 1]",
+        "INTEGER ARRAY NOT NULL");
+    f.checkNull("array_distinct(null)");
+  }

Review Comment:
   missing happy path:
   
   ```suggestion
       f.checkScalar("array_distinct(array[1, 2])", "[1, 2]",
           "INTEGER NOT NULL ARRAY NOT NULL");
   
       f.checkScalar("array_distinct(array[1])", "[1]",
           "INTEGER NOT NULL ARRAY NOT NULL");
     }
   ```



##########
site/_docs/reference.md:
##########
@@ -2647,6 +2647,7 @@ BigQuery's type system uses confusingly different names for types and functions:
 | m | expr1 <=> expr2                                | Whether two values are equal, treating null values as the same, and it's similar to `IS NOT DISTINCT FROM`
 | b | ARRAY_CONCAT(array [, array ]*)                | Concatenates one or more arrays. If any input argument is `NULL` the function returns `NULL`
 | b | ARRAY_LENGTH(array)                            | Synonym for `CARDINALITY`
+| b | ARRAY_DISTINCT(array)                          | Returns unique elements of *array*. Keeps ordering of elements.

Review Comment:
   s



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