Skip to content

Commit 6e86c22

Browse files
xiedeyantusilundong
authored andcommitted
[CALCITE-7350] Missing allowEmptyOutputFromRewrite parameter in TopDownGeneralDecorrelator.unnestInternal
1 parent 92cfb30 commit 6e86c22

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

core/src/main/java/org/apache/calcite/sql2rel/TopDownGeneralDecorrelator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ public RelNode unnestInternal(SetOp setOp, boolean allowEmptyOutputFromRewrite)
786786
return newSetOp;
787787
}
788788

789-
public RelNode unnestInternal(RelNode other) {
789+
public RelNode unnestInternal(RelNode other, boolean allowEmptyOutputFromRewrite) {
790790
throw new UnsupportedOperationException("Top-down general decorrelator does not support: "
791791
+ other.getClass().getSimpleName());
792792
}

core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10212,6 +10212,24 @@ public interface Config extends RelRule.Config {
1021210212
.check();
1021310213
}
1021410214

10215+
/** Test case for
10216+
* <a href="https://issues.apache.org/jira/browse/CALCITE-7350">[CALCITE-7350]
10217+
* Missing allowEmptyOutputFromRewrite parameter
10218+
* in TopDownGeneralDecorrelator.unnestInternal</a>. */
10219+
@Test void testUnnestInternalMissingParameter() {
10220+
final String sql = "SELECT empno FROM emp e"
10221+
+ " WHERE sal > some(SELECT avg(sal) over (partition by deptno) from emp_b b"
10222+
+ " where b.deptno = e.deptno)";
10223+
10224+
sql(sql)
10225+
.withRule(
10226+
CoreRules.FILTER_SUB_QUERY_TO_MARK_CORRELATE,
10227+
CoreRules.PROJECT_TO_LOGICAL_PROJECT_AND_WINDOW)
10228+
.withLateDecorrelate(true)
10229+
.withTopDownGeneralDecorrelate(true)
10230+
.check();
10231+
}
10232+
1021510233
/**
1021610234
* Test case for
1021710235
* <a href="https://issues.apache.org/jira/browse/CALCITE-6824">[CALCITE-6824]

core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21563,6 +21563,47 @@ LogicalProject(DEPTNO=[$7])
2156321563
<![CDATA[
2156421564
LogicalProject(DEPTNO=[$0], NAME=[$1])
2156521565
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
21566+
]]>
21567+
</Resource>
21568+
</TestCase>
21569+
<TestCase name="testUnnestInternalMissingParameter">
21570+
<Resource name="sql">
21571+
<![CDATA[SELECT empno FROM emp e WHERE sal > some(SELECT avg(sal) over (partition by deptno) from emp_b b where b.deptno = e.deptno)]]>
21572+
</Resource>
21573+
<Resource name="planBefore">
21574+
<![CDATA[
21575+
LogicalProject(EMPNO=[$0])
21576+
LogicalFilter(condition=[> SOME($5, {
21577+
LogicalProject(EXPR$0=[CAST(/(SUM($5) OVER (PARTITION BY $7), COUNT($5) OVER (PARTITION BY $7))):INTEGER NOT NULL])
21578+
LogicalFilter(condition=[=($7, $cor0.DEPTNO)])
21579+
LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
21580+
})], variablesSet=[[$cor0]])
21581+
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
21582+
]]>
21583+
</Resource>
21584+
<Resource name="planMid">
21585+
<![CDATA[
21586+
LogicalProject(EMPNO=[$0])
21587+
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
21588+
LogicalFilter(condition=[$9])
21589+
LogicalConditionalCorrelate(correlation=[$cor0], joinType=[left_mark], requiredColumns=[{7}], condition=[>($5, $9)])
21590+
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
21591+
LogicalProject(EXPR$0=[CAST(/($10, $11)):INTEGER NOT NULL])
21592+
LogicalWindow(window#0=[window(partition {7} aggs [SUM($5), COUNT($5)])])
21593+
LogicalFilter(condition=[=($7, $cor0.DEPTNO)])
21594+
LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
21595+
]]>
21596+
</Resource>
21597+
<Resource name="planAfter">
21598+
<![CDATA[
21599+
LogicalProject(EMPNO=[$0])
21600+
LogicalFilter(condition=[$9])
21601+
LogicalConditionalCorrelate(correlation=[$cor0], joinType=[left_mark], requiredColumns=[{7}], condition=[>($5, $9)])
21602+
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
21603+
LogicalProject(EXPR$0=[CAST(/($10, $11)):INTEGER NOT NULL])
21604+
LogicalWindow(window#0=[window(partition {7} aggs [SUM($5), COUNT($5)])])
21605+
LogicalFilter(condition=[=($7, $cor0.DEPTNO)])
21606+
LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
2156621607
]]>
2156721608
</Resource>
2156821609
</TestCase>

0 commit comments

Comments
 (0)