jinxing64 commented on a change in pull request #1468: [CALCITE-3366]
RelDecorrelator supports Union
URL: https://github.com/apache/calcite/pull/1468#discussion_r327600577
##########
File path: core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
##########
@@ -6349,6 +6349,47 @@ private MyProjectRule(Class<? extends Project> clazz,
String planAfter = NL + RelOptUtil.toString(relAfter);
getDiffRepos().assertEquals("planAfter", "${planAfter}", planAfter);
}
+
+ @Test public void testDecorrelateUnion0() {
+ final String sql = ""
+ + "SELECT deptno FROM dept where exists\n"
+ + "(SELECT 1 FROM emp where sal < 100 and emp.deptno=dept.deptno\n"
+ + "UNION ALL\n"
+ + "SELECT 1 FROM emp where sal > 200 and emp.deptno=dept.deptno)";
+ sql(sql)
+ .withLateDecorrelation(true)
+ .withTrim(true)
+ .with(HepProgram.builder().build())
+ .check();
+ }
+
+ @Test public void testDecorrelateUnion1() {
+ // Decorrelation would fail because the input frames of Union
+ // cannot match by row schema.
+ final String sql = "SELECT * FROM emp A where (deptno, sal) in \n"
+ + "(SELECT deptno, sal FROM emp\n"
+ + "UNION ALL\n"
+ + "SELECT deptno, sal FROM emp B where A.mgr = B.empno)";
Review comment:
Thanks for comment @danny0405
Yes, I believe so, it's a valid case.
But based on current implementation/mechanism of RelDecorrelator,
oldToNewOutputs and corDefOutputs should be derived and transferred from bottom
to up properly.
In such case, we cannot derive the `oldToNewOutputs` for Frame of Union and
this PR doesn't target to resolve such issue.
----------------------------------------------------------------
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