This is an automated email from the ASF dual-hosted git repository.

hyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/master by this push:
     new 758ce8b  [CALCITE-3021] ArrayEqualityComparer should use 
Arrays#deepEquals/deepHashCode instead of Arrays#equals/hashCode (Ruben Quesada 
Lopez)
758ce8b is described below

commit 758ce8b0eab0bfe59c7eefeedaf4cdd0d2235a10
Author: rubenada <[email protected]>
AuthorDate: Wed Apr 24 15:04:42 2019 +0200

    [CALCITE-3021] ArrayEqualityComparer should use 
Arrays#deepEquals/deepHashCode instead of Arrays#equals/hashCode (Ruben Quesada 
Lopez)
---
 core/src/test/resources/sql/struct.iq                     | 15 +++++++++++++++
 .../org/apache/calcite/linq4j/function/Functions.java     |  4 ++--
 .../java/org/apache/calcite/linq4j/test/Linq4jTest.java   | 15 +++++++++++++++
 3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/core/src/test/resources/sql/struct.iq 
b/core/src/test/resources/sql/struct.iq
index a62af30..46dba27 100644
--- a/core/src/test/resources/sql/struct.iq
+++ b/core/src/test/resources/sql/struct.iq
@@ -34,4 +34,19 @@ select * from (values
 !ok
 !}
 
+# [CALCITE-3021] ArrayEqualityComparer should use 
Arrays#deepEquals/deepHashCode instead of Arrays#equals/hashCode
+select distinct * from (values
+    (1, ROW(1,1)),
+    (1, ROW(1,1)),
+    (2, ROW(2,2))) as v(id,struct);
++----+--------+
+| ID | STRUCT |
++----+--------+
+|  1 | {1, 1} |
+|  2 | {2, 2} |
++----+--------+
+(2 rows)
+
+!ok
+
 # End struct.iq
diff --git 
a/linq4j/src/main/java/org/apache/calcite/linq4j/function/Functions.java 
b/linq4j/src/main/java/org/apache/calcite/linq4j/function/Functions.java
index b8f1caa..a013cde 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/function/Functions.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/function/Functions.java
@@ -465,11 +465,11 @@ public abstract class Functions {
   private static class ArrayEqualityComparer
       implements EqualityComparer<Object[]> {
     public boolean equal(Object[] v1, Object[] v2) {
-      return Arrays.equals(v1, v2);
+      return Arrays.deepEquals(v1, v2);
     }
 
     public int hashCode(Object[] t) {
-      return Arrays.hashCode(t);
+      return Arrays.deepHashCode(t);
     }
   }
 
diff --git 
a/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java 
b/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java
index e630485..0f24652 100644
--- a/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java
@@ -57,6 +57,8 @@ import java.util.NoSuchElementException;
 import java.util.Objects;
 import java.util.TreeSet;
 
+import static org.apache.calcite.linq4j.function.Functions.arrayComparer;
+
 import static org.hamcrest.CoreMatchers.endsWith;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.is;
@@ -907,6 +909,19 @@ public class Linq4jTest {
             .count());
   }
 
+  @Test public void testDistinctWithArrayEqualityComparer() {
+    final Object[][] items = {
+        {1, "a", new Object[]{1}},
+        {2, "b", new Object[]{2}},
+        {2, "b", new Object[]{2}},
+    };
+    assertEquals(
+        2,
+        Linq4j.asEnumerable(items)
+            .distinct(arrayComparer())
+            .count());
+  }
+
   @Test public void testGroupJoin() {
     // Note #1: Group join is a "left join": "bad employees" are filtered
     //   out, but empty departments are not.

Reply via email to