This is an automated email from the ASF dual-hosted git repository.
mbudiu 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 3488a78e7c [CALCITE-7289] Select NULL subquery throwing exception
3488a78e7c is described below
commit 3488a78e7c553bc0070b141e95103c6ecf51b7bf
Author: Mihai Budiu <[email protected]>
AuthorDate: Fri Nov 14 13:12:37 2025 -0800
[CALCITE-7289] Select NULL subquery throwing exception
Signed-off-by: Mihai Budiu <[email protected]>
---
.../java/org/apache/calcite/tools/RelBuilder.java | 7 ++++-
.../org/apache/calcite/test/RelOptRulesTest.java | 12 ++++++++
.../org/apache/calcite/test/RelOptRulesTest.xml | 34 ++++++++++++++++++++++
3 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
index b8500177c0..154cca84a3 100644
--- a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
+++ b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
@@ -1937,8 +1937,13 @@ public RelBuilder filter(Iterable<CorrelationId>
variablesSet,
if (config.simplify()) {
conjunctionPredicates = simplifier.simplifyFilterPredicates(predicates);
} else {
+ List<RexNode> simplified = new ArrayList<>();
+ for (RexNode predicate : predicates) {
+ RexNode simple = RexSimplify.simplifyComparisonWithNull(predicate,
getRexBuilder());
+ simplified.add(simple);
+ }
conjunctionPredicates =
- RexUtil.composeConjunction(simplifier.rexBuilder, predicates);
+ RexUtil.composeConjunction(simplifier.rexBuilder, simplified);
}
if (conjunctionPredicates == null ||
conjunctionPredicates.isAlwaysFalse()) {
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 2b429eac30..af463cbcb4 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -100,6 +100,7 @@
import org.apache.calcite.rel.rules.SortProjectTransposeRule;
import org.apache.calcite.rel.rules.SortUnionTransposeRule;
import org.apache.calcite.rel.rules.SpatialRules;
+import org.apache.calcite.rel.rules.SubQueryRemoveRule;
import org.apache.calcite.rel.rules.UnionMergeRule;
import org.apache.calcite.rel.rules.ValuesReduceRule;
import org.apache.calcite.rel.type.RelDataType;
@@ -9282,6 +9283,17 @@ private void checkSemiJoinRuleOnAntiJoin(RelOptRule
rule) {
.check();
}
+ /** Test case for <a
href="https://issues.apache.org/jira/browse/CALCITE-7289">[CALCITE-7289]
+ * Select NULL subquery throwing exception</a>. */
+ @Test void testNullSelect() {
+ final String sql = "SELECT 1 from emp WHERE NULL IN (SELECT null)";
+ RelBuilder.Config config =
+
RelBuilder.Config.DEFAULT.withSimplifyValues(false).withSimplify(false);
+ RelOptRule subQueryFilterRule =
+
SubQueryRemoveRule.Config.FILTER.withRelBuilderFactory(RelBuilder.proto(config)).toRule();
+ sql(sql).withRule(subQueryFilterRule).withLateDecorrelate(true).check();
+ }
+
/** Test case for
* <a
href="https://issues.apache.org/jira/browse/CALCITE-6652">[CALCITE-6652]
* RelDecorrelator can't decorrelate query with limit 1</a>.
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 bb53c538bd..a653e7e0d1 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -10723,6 +10723,40 @@ LogicalProject(DEPTNO=[$7])
<![CDATA[
LogicalProject(DEPTNO=[$0], NAME=[$1])
LogicalValues(tuples=[[]])
+]]>
+ </Resource>
+ </TestCase>
+ <TestCase name="testNullSelect">
+ <Resource name="sql">
+ <![CDATA[SELECT 1 from emp WHERE NULL IN (SELECT null)]]>
+ </Resource>
+ <Resource name="planBefore">
+ <![CDATA[
+LogicalProject(EXPR$0=[1])
+ LogicalFilter(condition=[IN(null:NULL, {
+LogicalValues(tuples=[[{ null }]])
+})])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+ </Resource>
+ <Resource name="planMid">
+ <![CDATA[
+LogicalProject(EXPR$0=[1])
+ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4],
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
+ LogicalJoin(condition=[true], joinType=[inner])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalProject(cs=[true])
+ LogicalValues(tuples=[[]])
+]]>
+ </Resource>
+ <Resource name="planAfter">
+ <![CDATA[
+LogicalProject(EXPR$0=[1])
+ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4],
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
+ LogicalJoin(condition=[true], joinType=[inner])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalProject(cs=[true])
+ LogicalValues(tuples=[[]])
]]>
</Resource>
</TestCase>