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

jcamacho 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 9ece70f  [CALCITE-3012] Column uniqueness metadata provider may return 
wrong result for FULL OUTER JOIN operator (Vineet Garg)
9ece70f is described below

commit 9ece70f5dcdb00dbc6712496c51f52c05178d4aa
Author: Vineet Garg <[email protected]>
AuthorDate: Sat Apr 27 15:11:33 2019 -0700

    [CALCITE-3012] Column uniqueness metadata provider may return wrong result 
for FULL OUTER JOIN operator (Vineet Garg)
    
    Close apache/calcite#1185
---
 .../calcite/rel/metadata/RelMdColumnUniqueness.java       |  8 ++++++++
 .../java/org/apache/calcite/test/RelMetadataTest.java     | 15 +++++++++++++++
 2 files changed, 23 insertions(+)

diff --git 
a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnUniqueness.java 
b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnUniqueness.java
index e9625fa..a6cd23c 100644
--- 
a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnUniqueness.java
+++ 
b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdColumnUniqueness.java
@@ -27,6 +27,7 @@ import org.apache.calcite.rel.core.Filter;
 import org.apache.calcite.rel.core.Intersect;
 import org.apache.calcite.rel.core.Join;
 import org.apache.calcite.rel.core.JoinInfo;
+import org.apache.calcite.rel.core.JoinRelType;
 import org.apache.calcite.rel.core.Minus;
 import org.apache.calcite.rel.core.Project;
 import org.apache.calcite.rel.core.SemiJoin;
@@ -254,6 +255,13 @@ public class RelMdColumnUniqueness
     final ImmutableBitSet leftColumns = leftAndRightColumns.left;
     final ImmutableBitSet rightColumns = leftAndRightColumns.right;
 
+    // for FULL OUTER JOIN if columns contain column from both inputs it is not
+    // guaranteed that the result will be unique
+    if (!ignoreNulls && rel.getJoinType() == JoinRelType.FULL
+        && leftColumns.cardinality() > 0 && rightColumns.cardinality() > 0) {
+      return false;
+    }
+
     // If the original column mask contains columns from both the left and
     // right hand side, then the columns are unique if and only if they're
     // unique for their respective join inputs
diff --git a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java 
b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
index 85b4ba2..7a91292 100644
--- a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
@@ -925,6 +925,21 @@ public class RelMetadataTest extends SqlToRelTestBase {
     assertUniqueConsistent(rel);
   }
 
+  @Test public void testFullOuterJoinUniqueness1() {
+    final String sql = "select e.empno, d.deptno \n"
+        + "from (select cast(null as int) empno from sales.emp "
+        + " where empno = 10 group by cast(null as int)) as e \n"
+        + "full outer join (select cast (null as int) deptno from sales.dept "
+        + "group by cast(null as int)) as d on e.empno = d.deptno \n"
+        + "group by e.empno, d.deptno";
+    RelNode rel = convertSql(sql);
+    final RelMetadataQuery mq = RelMetadataQuery.instance();
+    final ImmutableBitSet allCols =
+        ImmutableBitSet.range(0, rel.getRowType().getFieldCount());
+    Boolean areGroupByKeysUnique = mq.areColumnsUnique(rel.getInput(0), 
allCols);
+    assertThat(areGroupByKeysUnique, is(false));
+  }
+
   @Test public void testGroupBy() {
     RelNode rel = convertSql("select deptno, count(*), sum(sal) from emp\n"
             + "group by deptno");

Reply via email to