tkalkirill commented on code in PR #5305:
URL: https://github.com/apache/calcite/pull/5305#discussion_r4192928719


##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -7334,17 +7343,77 @@ public static List arrayExcept(List list1, List list2) {
 
   /** 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);
+    final Set<@Nullable Object> result = toDeepEqualitySet(list1);
+    result.retainAll(toDeepEqualitySet(list2));
+    return unwrapDeepEqualitySet(result);
   }
 
   /** Support the ARRAY_UNION function. */
   public static List arrayUnion(List list1, List list2) {
-    final Set result = new LinkedHashSet<>();
-    result.addAll(list1);
-    result.addAll(list2);
-    return new ArrayList<>(result);
+    final Set<@Nullable Object> result = toDeepEqualitySet(list1);
+    for (Object element : list2) {
+      result.add(deepKey(element));
+    }
+    return unwrapDeepEqualitySet(result);
+  }
+
+  /** Creates keys in encounter order, retaining the first equal value. */

Review Comment:
   Agreed, “keys” is misleading here; I'll use “set” and “elements”. The 
[documentation](https://calcite.apache.org/docs/reference.html#dialect-specific-operators)
 (find ARRAY_DISTINCT) explicitly states that `ARRAY_DISTINCT` preserves 
element order. The previous implementation also used `LinkedHashSet`, so this 
retains the existing behavior.



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