This is an automated email from the ASF dual-hosted git repository.
silun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new 6e86c227ed [CALCITE-7350] Missing allowEmptyOutputFromRewrite
parameter in TopDownGeneralDecorrelator.unnestInternal
6e86c227ed is described below
commit 6e86c227edf14a73ee49535f472925abf6ee98dd
Author: Zhen Chen <[email protected]>
AuthorDate: Sat Jan 3 16:36:58 2026 +0800
[CALCITE-7350] Missing allowEmptyOutputFromRewrite parameter in
TopDownGeneralDecorrelator.unnestInternal
---
.../sql2rel/TopDownGeneralDecorrelator.java | 2 +-
.../org/apache/calcite/test/RelOptRulesTest.java | 18 ++++++++++
.../org/apache/calcite/test/RelOptRulesTest.xml | 41 ++++++++++++++++++++++
3 files changed, 60 insertions(+), 1 deletion(-)
diff --git
a/core/src/main/java/org/apache/calcite/sql2rel/TopDownGeneralDecorrelator.java
b/core/src/main/java/org/apache/calcite/sql2rel/TopDownGeneralDecorrelator.java
index cea5e5d5a4..d3ccaa334d 100644
---
a/core/src/main/java/org/apache/calcite/sql2rel/TopDownGeneralDecorrelator.java
+++
b/core/src/main/java/org/apache/calcite/sql2rel/TopDownGeneralDecorrelator.java
@@ -786,7 +786,7 @@ public RelNode unnestInternal(SetOp setOp, boolean
allowEmptyOutputFromRewrite)
return newSetOp;
}
- public RelNode unnestInternal(RelNode other) {
+ public RelNode unnestInternal(RelNode other, boolean
allowEmptyOutputFromRewrite) {
throw new UnsupportedOperationException("Top-down general decorrelator
does not support: "
+ other.getClass().getSimpleName());
}
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index 959cdada0b..1afbae4519 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -10212,6 +10212,24 @@ public interface Config extends RelRule.Config {
.check();
}
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7350">[CALCITE-7350]
+ * Missing allowEmptyOutputFromRewrite parameter
+ * in TopDownGeneralDecorrelator.unnestInternal</a>. */
+ @Test void testUnnestInternalMissingParameter() {
+ final String sql = "SELECT empno FROM emp e"
+ + " WHERE sal > some(SELECT avg(sal) over (partition by deptno) from
emp_b b"
+ + " where b.deptno = e.deptno)";
+
+ sql(sql)
+ .withRule(
+ CoreRules.FILTER_SUB_QUERY_TO_MARK_CORRELATE,
+ CoreRules.PROJECT_TO_LOGICAL_PROJECT_AND_WINDOW)
+ .withLateDecorrelate(true)
+ .withTopDownGeneralDecorrelate(true)
+ .check();
+ }
+
/**
* Test case for
* <a
href="https://issues.apache.org/jira/browse/CALCITE-6824">[CALCITE-6824]
diff --git
a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
index 7075571d95..3887c4fe50 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -21563,6 +21563,47 @@ LogicalProject(DEPTNO=[$7])
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+]]>
+ </Resource>
+ </TestCase>
+ <TestCase name="testUnnestInternalMissingParameter">
+ <Resource name="sql">
+ <![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)]]>
+ </Resource>
+ <Resource name="planBefore">
+ <![CDATA[
+LogicalProject(EMPNO=[$0])
+ LogicalFilter(condition=[> SOME($5, {
+LogicalProject(EXPR$0=[CAST(/(SUM($5) OVER (PARTITION BY $7), COUNT($5) OVER
(PARTITION BY $7))):INTEGER NOT NULL])
+ LogicalFilter(condition=[=($7, $cor0.DEPTNO)])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
+})], variablesSet=[[$cor0]])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+ </Resource>
+ <Resource name="planMid">
+ <![CDATA[
+LogicalProject(EMPNO=[$0])
+ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4],
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
+ LogicalFilter(condition=[$9])
+ LogicalConditionalCorrelate(correlation=[$cor0], joinType=[left_mark],
requiredColumns=[{7}], condition=[>($5, $9)])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalProject(EXPR$0=[CAST(/($10, $11)):INTEGER NOT NULL])
+ LogicalWindow(window#0=[window(partition {7} aggs [SUM($5),
COUNT($5)])])
+ LogicalFilter(condition=[=($7, $cor0.DEPTNO)])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
+]]>
+ </Resource>
+ <Resource name="planAfter">
+ <![CDATA[
+LogicalProject(EMPNO=[$0])
+ LogicalFilter(condition=[$9])
+ LogicalConditionalCorrelate(correlation=[$cor0], joinType=[left_mark],
requiredColumns=[{7}], condition=[>($5, $9)])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalProject(EXPR$0=[CAST(/($10, $11)):INTEGER NOT NULL])
+ LogicalWindow(window#0=[window(partition {7} aggs [SUM($5),
COUNT($5)])])
+ LogicalFilter(condition=[=($7, $cor0.DEPTNO)])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP_B]])
]]>
</Resource>
</TestCase>