[GitHub] [calcite] JiajunBernoulli commented on a diff in pull request #3202: [CALCITE-5704] Add ARRAY_EXCEPT, ARRAY_INTERSECT, ARRAY_UNION function (enabled in Spark library)

2023-06-03 Thread via GitHub


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


##
site/_docs/reference.md:
##
@@ -2653,11 +2653,14 @@ BigQuery's type system uses confusingly different names 
for types and functions:
 | * | ACOSH(numeric) | Returns the inverse 
hyperbolic cosine of *numeric*
 | s | ARRAY(expr [, expr ]*) | Construct an array in 
Apache Spark
 | b | ARRAY_CONCAT(array [, array ]*)| Concatenates one or 
more arrays. If any input argument is `NULL` the function returns `NULL`
-| s | ARRAY_DISTINCT(array)  | Returns unique elements 
of *array*. Keeps ordering of elements.
+| s | ARRAY_DISTINCT(array)  | Returns unique elements 
of *array*. Keeps ordering of elements

Review Comment:
   In fact, `Keeps ordering of elements` is a sentence that I'm worried about.
   
   This sentence lacks a subject, I hope the description is close to natural 
language.
   For example:
   `Removes duplicate values from the *array* that keeps ordering of elements`.



-- 
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-unsubscr...@calcite.apache.org

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



[GitHub] [calcite] JiajunBernoulli commented on a diff in pull request #3202: [CALCITE-5704] Add ARRAY_EXCEPT, ARRAY_INTERSECT, ARRAY_UNION function (enabled in Spark library)

2023-06-03 Thread via GitHub


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


##
site/_docs/reference.md:
##
@@ -2653,11 +2653,14 @@ BigQuery's type system uses confusingly different names 
for types and functions:
 | * | ACOSH(numeric) | Returns the inverse 
hyperbolic cosine of *numeric*
 | s | ARRAY(expr [, expr ]*) | Construct an array in 
Apache Spark
 | b | ARRAY_CONCAT(array [, array ]*)| Concatenates one or 
more arrays. If any input argument is `NULL` the function returns `NULL`
-| s | ARRAY_DISTINCT(array)  | Returns unique elements 
of *array*. Keeps ordering of elements.
+| s | ARRAY_DISTINCT(array)  | Returns unique elements 
of *array*. Keeps ordering of elements

Review Comment:
   In fact, Keeps ordering of elements is a sentence that I'm worried about.
   
   This sentence lacks a subject, I hope the description is close to natural 
language.
   For example:
   Removes duplicate values from the *array* that keeps ordering of elements.



-- 
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-unsubscr...@calcite.apache.org

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



[GitHub] [calcite] JiajunBernoulli commented on a diff in pull request #3202: [CALCITE-5704] Add ARRAY_EXCEPT, ARRAY_INTERSECT, ARRAY_UNION function (enabled in Spark library)

2023-06-03 Thread via GitHub


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


##
site/_docs/reference.md:
##
@@ -2654,11 +2654,14 @@ BigQuery's type system uses confusingly different names 
for types and functions:
 | s | ARRAY(expr [, expr ]*) | Construct an array in 
Apache Spark
 | s | ARRAY_COMPACT(array)   | Removes null values 
from the *array*
 | b | ARRAY_CONCAT(array [, array ]*)| Concatenates one or 
more arrays. If any input argument is `NULL` the function returns `NULL`
-| s | ARRAY_DISTINCT(array)  | Returns unique elements 
of *array*. Keeps ordering of elements.
+| s | ARRAY_DISTINCT(array)  | Removes duplicate 
values from the *array*. Keeps ordering of elements

Review Comment:
   In fact, `Keeps ordering of elements` is a sentence that I'm worried about.
   
   This sentence lacks a subject, I hope the description is close to natural 
language.
   For example:
   `Removes duplicate values from the *array* that keeps ordering of elements`
   
   



-- 
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-unsubscr...@calcite.apache.org

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



[GitHub] [calcite] JiajunBernoulli commented on a diff in pull request #3202: [CALCITE-5704] Add ARRAY_EXCEPT, ARRAY_INTERSECT, ARRAY_UNION function (enabled in Spark library)

2023-06-02 Thread via GitHub


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


##
site/_docs/reference.md:
##
@@ -2653,11 +2653,14 @@ BigQuery's type system uses confusingly different names 
for types and functions:
 | * | ACOSH(numeric) | Returns the inverse 
hyperbolic cosine of *numeric*
 | s | ARRAY(expr [, expr ]*) | Construct an array in 
Apache Spark
 | b | ARRAY_CONCAT(array [, array ]*)| Concatenates one or 
more arrays. If any input argument is `NULL` the function returns `NULL`
-| s | ARRAY_DISTINCT(array)  | Returns unique elements 
of *array*. Keeps ordering of elements.
+| s | ARRAY_DISTINCT(array)  | Returns unique elements 
of *array*. Keeps ordering of elements

Review Comment:
   `Returns unique elements that keep ordering of elements of *array*`



-- 
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-unsubscr...@calcite.apache.org

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



[GitHub] [calcite] JiajunBernoulli commented on a diff in pull request #3202: [CALCITE-5704] Add ARRAY_EXCEPT, ARRAY_INTERSECT, ARRAY_UNION function (enabled in Spark library)

2023-06-02 Thread via GitHub


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


##
site/_docs/reference.md:
##
@@ -2653,11 +2653,14 @@ BigQuery's type system uses confusingly different names 
for types and functions:
 | * | ACOSH(numeric) | Returns the inverse 
hyperbolic cosine of *numeric*
 | s | ARRAY(expr [, expr ]*) | Construct an array in 
Apache Spark
 | b | ARRAY_CONCAT(array [, array ]*)| Concatenates one or 
more arrays. If any input argument is `NULL` the function returns `NULL`
-| s | ARRAY_DISTINCT(array)  | Returns unique elements 
of *array*. Keeps ordering of elements.
+| s | ARRAY_DISTINCT(array)  | Returns unique elements 
of *array*. Keeps ordering of elements

Review Comment:
   Maybe `Removes duplicate values from the *array*`
   
   https://spark.apache.org/docs/latest/api/sql/#array_distinct



-- 
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-unsubscr...@calcite.apache.org

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



[GitHub] [calcite] JiajunBernoulli commented on a diff in pull request #3202: [CALCITE-5704] Add ARRAY_EXCEPT, ARRAY_INTERSECT, ARRAY_UNION function (enabled in Spark library)

2023-06-02 Thread via GitHub


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


##
site/_docs/reference.md:
##
@@ -2653,11 +2653,14 @@ BigQuery's type system uses confusingly different names 
for types and functions:
 | * | ACOSH(numeric) | Returns the inverse 
hyperbolic cosine of *numeric*
 | s | ARRAY(expr [, expr ]*) | Construct an array in 
Apache Spark
 | b | ARRAY_CONCAT(array [, array ]*)| Concatenates one or 
more arrays. If any input argument is `NULL` the function returns `NULL`
-| s | ARRAY_DISTINCT(array)  | Returns unique elements 
of *array*. Keeps ordering of elements.
+| s | ARRAY_DISTINCT(array)  | Returns unique elements 
of *array*. Keeps ordering of elements

Review Comment:
   Returns unique elements that keep ordering of elements of *array*



-- 
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-unsubscr...@calcite.apache.org

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



[GitHub] [calcite] JiajunBernoulli commented on a diff in pull request #3202: [CALCITE-5704] Add ARRAY_EXCEPT, ARRAY_INTERSECT, ARRAY_UNION function (enabled in Spark library)

2023-05-20 Thread via GitHub


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


##
core/src/main/java/org/apache/calcite/sql/type/ArrayOperandTypeChecker.java:
##
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql.type;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlCallBinding;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperandCountRange;
+import org.apache.calcite.sql.SqlOperator;
+
+import com.google.common.collect.ImmutableList;
+
+import static 
org.apache.calcite.sql.type.NonNullableAccessors.getComponentTypeOrThrow;
+import static org.apache.calcite.util.Static.RESOURCE;
+
+/**
+ * Parameter type-checking strategy where types must be ([nullable] Array,
+ * [nullable] Array), and the two types must have the same element type.
+ *
+ * @see ArraySqlType#getComponentType
+ */
+public class ArrayOperandTypeChecker implements SqlOperandTypeChecker {

Review Comment:
   Look like `MultisetOperandTypeChecker`



##
core/src/main/java/org/apache/calcite/sql/type/ArrayOperandTypeChecker.java:
##
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql.type;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlCallBinding;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperandCountRange;
+import org.apache.calcite.sql.SqlOperator;
+
+import com.google.common.collect.ImmutableList;
+
+import static 
org.apache.calcite.sql.type.NonNullableAccessors.getComponentTypeOrThrow;
+import static org.apache.calcite.util.Static.RESOURCE;
+
+/**
+ * Parameter type-checking strategy where types must be ([nullable] Array,
+ * [nullable] Array), and the two types must have the same element type.
+ *
+ * @see ArraySqlType#getComponentType
+ */
+public class ArrayOperandTypeChecker implements SqlOperandTypeChecker {

Review Comment:
   Look like `MultisetOperandTypeChecker`.



-- 
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-unsubscr...@calcite.apache.org

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



[GitHub] [calcite] JiajunBernoulli commented on a diff in pull request #3202: [CALCITE-5704] Add ARRAY_EXCEPT, ARRAY_INTERSECT, ARRAY_UNION function (enabled in Spark library)

2023-05-20 Thread via GitHub


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


##
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##
@@ -3809,6 +3809,29 @@ public static List distinct(List list) {
 return Collections.nCopies(numberOfElement, element);
   }
 
+  /** Support the ARRAY_EXCEPT function. */
+  public static List arrayExcept(List list1, List list2) {
+final Set result = new LinkedHashSet<>(list1);
+result.removeAll(list2);
+return new ArrayList<>(result);
+  }
+
+  /** Support the ARRAY_INTERSECT function. */
+  public static List arrayIntersect(List list1, List list2) {
+final Set result = new LinkedHashSet<>(list1);
+result.retainAll(list2);
+return new ArrayList<>(result);
+  }
+
+  /** Support the ARRAY_UNION function. */
+  public static List arrayUnion(List list1, List list2) {
+final Set result =
+new LinkedHashSet<>(Math.max((int) ((list1.size() + list2.size()) / 
.75f) + 1, 16));

Review Comment:
   Defining some variables will make it easier to understand.
   `Math.max((int) ((list1.size() + list2.size()) / .75f) + 1, 16)`.
why `.75f`, why `16`?



-- 
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-unsubscr...@calcite.apache.org

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



[GitHub] [calcite] JiajunBernoulli commented on a diff in pull request #3202: [CALCITE-5704] Add ARRAY_EXCEPT, ARRAY_INTERSECT, ARRAY_UNION function (enabled in Spark library)

2023-05-20 Thread via GitHub


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


##
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##
@@ -3809,6 +3809,29 @@ public static List distinct(List list) {
 return Collections.nCopies(numberOfElement, element);
   }
 
+  /** Support the ARRAY_EXCEPT function. */
+  public static List arrayExcept(List list1, List list2) {
+final Set result = new LinkedHashSet<>(list1);
+result.removeAll(list2);
+return new ArrayList<>(result);
+  }
+
+  /** Support the ARRAY_INTERSECT function. */
+  public static List arrayIntersect(List list1, List list2) {
+final Set result = new LinkedHashSet<>(list1);
+result.retainAll(list2);
+return new ArrayList<>(result);
+  }
+
+  /** Support the ARRAY_UNION function. */
+  public static List arrayUnion(List list1, List list2) {
+final Set result =
+new LinkedHashSet<>(Math.max((int) ((list1.size() + list2.size()) / 
.75f) + 1, 16));

Review Comment:
   Defining some variables will make it easier to understand, why `.75f`, why 
16?
   `Math.max((int) ((list1.size() + list2.size()) / .75f) + 1, 16)`.



-- 
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-unsubscr...@calcite.apache.org

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