jinxing64 commented on a change in pull request #1466: [CALCITE-3363] 
JoinUnionTransposeRule.RIGHT_UNION should not match ANTI join
URL: https://github.com/apache/calcite/pull/1466#discussion_r326908067
 
 

 ##########
 File path: core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
 ##########
 @@ -1778,6 +1778,53 @@ private void 
basePushFilterPastAggWithGroupingSets(boolean unchanged)
             + "(select * from emp e1 union all select * from emp e2) r2");
   }
 
+  @Test public void testPushJoinThroughUnionOnRightDoesNotMatchAntiJoin() {
+    final RelBuilder builder = 
RelBuilder.create(RelBuilderTest.config().build());
+
+    // build a rel equivalent to sql:
+    // select r1.sal from
+    // emp r1 where r1.deptno not in
+    //  (select deptno from dept d1 where deptno < 10
+    //  union all
+    //  select deptno from dept d2 where deptno > 20)
+    RelNode left = builder.scan("EMP").build();
+    RelNode right = builder
+        .scan("DEPT")
+        .filter(
+            builder.call(SqlStdOperatorTable.LESS_THAN,
+                builder.field("DEPTNO"),
+                builder.literal(10)))
+        .project(builder.field("DEPTNO"))
+        .scan("DEPT")
+        .filter(
+            builder.call(SqlStdOperatorTable.GREATER_THAN,
+                builder.field("DEPTNO"),
+                builder.literal(20)))
+        .project(builder.field("DEPTNO"))
+        .union(true)
+        .build();
+    RelNode relNode = builder.push(left).push(right)
+        .antiJoin(
+            builder.call(SqlStdOperatorTable.EQUALS,
+                builder.field(2, 0, "DEPTNO"),
+                builder.field(2, 1, "DEPTNO")))
+        .project(builder.field("SAL"))
+        .build();
 
 Review comment:
   hmm, I tried, but failed for below two issues:
   CALCITE-3366 -- currently `RelDecorrelator` doesn't support decorrelation 
for Union
   CALCITE-3367 -- I cannot find a proper way to construct a semi-join just 
like SemiJoinRule, i.e. RelOptRulesTest#testSemiJoinRuleExists
   
   I made fixes for the above two issues in 
https://github.com/apache/calcite/pull/1468 and 
https://github.com/apache/calcite/pull/1469
   It's great if you can take a look when you have time

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to