JiajunBernoulli commented on code in PR #3198:
URL: https://github.com/apache/calcite/pull/3198#discussion_r1193118402


##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -5349,6 +5368,21 @@ private static void checkIf(SqlOperatorFixture f) {
         "INTEGER ARRAY NOT NULL");
   }
 
+  /** Tests {@code ARRAY_SIZE} function from Spark. */
+  @Test void testArraySizeFunc() {
+    final SqlOperatorFixture f0 = fixture();
+    f0.setFor(SqlLibraryOperators.ARRAY_SIZE);
+    f0.checkFails("^array_size(array[1])^",
+        "No match found for function signature ARRAY_SIZE\\(<INTEGER 
ARRAY>\\)", false);
+
+    final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.SPARK);
+    f.checkScalar("array_size(array[1])", "1",

Review Comment:
   Same as above.



##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -5336,6 +5336,25 @@ private static void checkIf(SqlOperatorFixture f) {
     f.checkNull("array_distinct(null)");
   }
 
+  /** Tests {@code ARRAY_REPEAT} function from Spark. */
+  @Test void testArrayRepeatFunc() {
+    final SqlOperatorFixture f0 = fixture();
+    f0.setFor(SqlLibraryOperators.ARRAY_REPEAT);
+    f0.checkFails("^array_repeat(1, 2)^",
+        "No match found for function signature ARRAY_REPEAT\\(<NUMERIC>, 
<NUMERIC>\\)", false);
+
+    final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.SPARK);
+    f.checkScalar("array_repeat(1, 2)", "[1, 1]",
+        "INTEGER NOT NULL ARRAY NOT NULL");
+    f.checkScalar("array_repeat(array[1, 2], 2)", "[[1, 2], [1, 2]]",
+        "INTEGER NOT NULL ARRAY NOT NULL ARRAY NOT NULL");
+    f.checkScalar("array_repeat(map[1, 'a', 2, 'b'], 2)", "[{1=a, 2=b}, {1=a, 
2=b}]",
+        "(INTEGER NOT NULL, CHAR(1) NOT NULL) MAP NOT NULL ARRAY NOT NULL");
+    f.checkScalar("array_repeat(cast(null as integer), 2)", "[null, null]",
+        "INTEGER ARRAY NOT NULL");

Review Comment:
   The element is null, type should nullable.



##########
core/src/main/java/org/apache/calcite/util/BuiltInMethod.java:
##########
@@ -629,6 +629,7 @@ public enum BuiltInMethod {
   SUBMULTISET_OF(SqlFunctions.class, "submultisetOf", Collection.class,
       Collection.class),
   ARRAY_DISTINCT(SqlFunctions.class, "distinct", List.class),
+  ARRAY_REPEAT(SqlFunctions.class, "repeat", Object.class, Integer.class),

Review Comment:
   Would Long.class be better?



##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -5336,6 +5336,25 @@ private static void checkIf(SqlOperatorFixture f) {
     f.checkNull("array_distinct(null)");
   }
 
+  /** Tests {@code ARRAY_REPEAT} function from Spark. */
+  @Test void testArrayRepeatFunc() {
+    final SqlOperatorFixture f0 = fixture();
+    f0.setFor(SqlLibraryOperators.ARRAY_REPEAT);
+    f0.checkFails("^array_repeat(1, 2)^",
+        "No match found for function signature ARRAY_REPEAT\\(<NUMERIC>, 
<NUMERIC>\\)", false);
+
+    final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.SPARK);
+    f.checkScalar("array_repeat(1, 2)", "[1, 1]",

Review Comment:
   If count <= 0, it is easy to understand for error message?



##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -3797,6 +3797,14 @@ public static List distinct(List list) {
     return new ArrayList<>(result);
   }
 
+  /** Support the ARRAY_REPEAT function. */
+  public static @Nullable List repeat(Object element, Object count) {
+    if (count == null) {
+      return null;
+    }
+    return Collections.nCopies((Integer) count, element);

Review Comment:
   Can it be Long?
   
   I am worried that the Integer will fail for Long.



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