This is an automated email from the ASF dual-hosted git repository.
asolimando 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 20d503d3b6 Revert "[CALCITE-6978] Translation to relational algebra of
correlated query with COALESCE causes an assertion failure"
20d503d3b6 is described below
commit 20d503d3b697779bec7e102977bd89107086661d
Author: Alessandro Solimando <[email protected]>
AuthorDate: Thu May 22 20:22:06 2025 +0200
Revert "[CALCITE-6978] Translation to relational algebra of correlated
query with COALESCE causes an assertion failure"
This reverts commit 60e1b72fa164f0e06740bd3bf3f46a9725a87ab8.
Reverting as CALCITE-7035 highlighted issues for missing rewrites of calls
without implementors/converlet
This issue will be addressed by CALCITE-7012
---
.../apache/calcite/sql/validate/SqlValidatorImpl.java | 4 +---
.../org/apache/calcite/test/SqlToRelConverterTest.java | 12 ------------
.../org/apache/calcite/test/SqlToRelConverterTest.xml | 17 -----------------
core/src/test/resources/sql/sub-query.iq | 2 +-
4 files changed, 2 insertions(+), 33 deletions(-)
diff --git
a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
index ba2330dce5..dae940982a 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
@@ -1528,9 +1528,7 @@ private void handleOffsetFetch(@Nullable SqlNode offset,
@Nullable SqlNode fetch
((SqlBasicCall) call).setOperator(overloads.get(0));
}
}
- if (config.callRewrite()
- // Do not rewrite calls that contain subqueries
- && !SqlUtil.containsCall(call, c -> c.getKind() == SqlKind.SELECT)) {
+ if (config.callRewrite()) {
node = call.getOperator().rewriteCall(this, call);
}
} else if (node instanceof SqlNodeList) {
diff --git
a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
index 41b1f0d757..50e5eec2ab 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -1678,18 +1678,6 @@ public static void checkActualAndReferenceFiles() {
sql(sql).ok();
}
- /** Test case for <a
href="https://issues.apache.org/jira/browse/CALCITE-6978">[CALCITE-6978]
- * Translation to relational algebra of correlated query with COALESCE
causes an
- * assertion failure</a>. */
- @Test void testCoalesceSubquery() {
- final String sql = "SELECT"
- + " deptno, "
- + " coalesce((select sum(empno) from emp "
- + " where deptno = emp.deptno limit 1), 0) as w "
- + "FROM dept";
- sql(sql).ok();
- }
-
@Test void testSampleBernoulliQuery() {
final String sql = "select * from (\n"
+ " select * from emp as e tablesample bernoulli(10) repeatable(1)\n"
diff --git
a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
index 1008b04c9f..2dcbe1f413 100644
--- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
@@ -651,23 +651,6 @@ LogicalProject(EXPR$0=[CHAR_LENGTH('foo')])
<![CDATA[
LogicalProject(EXPR$0=[CASE(IS NOT NULL($3), CAST($3):INTEGER NOT NULL, 0)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
-]]>
- </Resource>
- </TestCase>
- <TestCase name="testCoalesceSubquery">
- <Resource name="sql">
- <![CDATA[SELECT deptno, coalesce((select sum(empno) from emp where
deptno = emp.deptno limit 1), 0) as w FROM dept]]>
- </Resource>
- <Resource name="plan">
- <![CDATA[
-LogicalProject(DEPTNO=[$0], W=[COALESCE($2, 0)])
- LogicalJoin(condition=[true], joinType=[left])
- LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
- LogicalSort(fetch=[1])
- LogicalAggregate(group=[{}], EXPR$0=[SUM($0)])
- LogicalProject(EMPNO=[$0])
- LogicalFilter(condition=[=($7, $7)])
- LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
diff --git a/core/src/test/resources/sql/sub-query.iq
b/core/src/test/resources/sql/sub-query.iq
index 12f7e1e8cc..8a3787d07f 100644
--- a/core/src/test/resources/sql/sub-query.iq
+++ b/core/src/test/resources/sql/sub-query.iq
@@ -1134,7 +1134,7 @@ EnumerableCalc(expr#0..3=[{inputs}], ENAME=[$t1],
DEEP2SAL=[$t3])
EnumerableTableScan(table=[[scott, EMP]])
EnumerableSort(sort0=[$0], dir0=[ASC])
EnumerableAggregate(group=[{0}], EXPR$0=[SUM($1)])
- EnumerableCalc(expr#0..4=[{inputs}], expr#5=[0], expr#6=[COALESCE($t4,
$t5)], expr#7=[+($t2, $t6)], MGR9=[$t1], $f0=[$t7])
+ EnumerableCalc(expr#0..4=[{inputs}], expr#5=[IS NOT NULL($t4)],
expr#6=[0.00:DECIMAL(19, 2)], expr#7=[CASE($t5, $t4, $t6)], expr#8=[+($t2,
$t7)], MGR9=[$t1], $f0=[$t8])
EnumerableMergeJoin(condition=[=($0, $3)], joinType=[left])
EnumerableCalc(expr#0..7=[{inputs}], expr#8=[IS NOT NULL($t3)],
EMPNO=[$t0], MGR=[$t3], SAL=[$t5], $condition=[$t8])
EnumerableTableScan(table=[[scott, EMP]])