zabetak commented on a change in pull request #2385:
URL: https://github.com/apache/calcite/pull/2385#discussion_r656989338



##########
File path: core/src/main/java/org/apache/calcite/tools/RelBuilder.java
##########
@@ -2422,18 +2422,16 @@ public RelBuilder join(JoinRelType joinType, RexNode 
condition,
     }
     if (correlate) {
       final CorrelationId id = Iterables.getOnlyElement(variablesSet);
-      if (!RelOptUtil.notContainsCorrelation(left.rel, id, Litmus.IGNORE)) {
-        throw new IllegalArgumentException("variable " + id
-            + " must not be used by left input to correlation");
-      }
       // Correlate does not have an ON clause.
       switch (joinType) {
       case LEFT:
       case SEMI:
       case ANTI:
         // For a LEFT/SEMI/ANTI, predicate must be evaluated first.
         stack.push(right);
-        filter(condition.accept(new Shifter(left.rel, id, right.rel)));
+        filter(
+            RelOptUtil.correlateLeftShiftRight(getRexBuilder(),
+                left.rel, id, right.rel, condition));

Review comment:
       Let's consider for instance the following plans which can be produced 
with the code before and after the changes in this PR.
   
   ```
   LogicalProject(DEPTNO=[$0], EMPNO=[$3])
     LogicalCorrelate(correlation=[$cor0], joinType=[left], 
requiredColumns=[{0}])
       LogicalTableScan(table=[[scott, DEPT]])
       LogicalFilter(condition=[=($cor0.DEPTNO, $7)])
         LogicalSort(sort0=[$5], dir0=[ASC], fetch=[2])
           LogicalTableScan(table=[[scott, EMP]])
   
   LogicalProject(DEPTNO=[$0], EMPNO=[$3])
     LogicalJoin(condition=[=($0, $10)], joinType=[left])
       LogicalTableScan(table=[[scott, DEPT]])
       LogicalSort(sort0=[$5], dir0=[ASC], fetch=[2])
         LogicalTableScan(table=[[scott, EMP]])
   ```
   What I would like to make sure is that whatever is under the right side of 
the join/correlate+filter  does not give different results if we switch from 
correlate+filter to join. I need to find some time to think on it a bit more.




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


Reply via email to