This is an automated email from the ASF dual-hosted git repository.
michaelsmith pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git
The following commit(s) were added to refs/heads/master by this push:
new 02d2e168c IMPALA-14525 addendum: For simplify, nulls should only be
treated as false for filters
02d2e168c is described below
commit 02d2e168cca7f321bc01d23dcf5a78f3c0891563
Author: Steve Carlin <[email protected]>
AuthorDate: Sun Feb 8 07:29:22 2026 -0800
IMPALA-14525 addendum: For simplify, nulls should only be treated as false
for filters
The previous fix for IMPALA-14525 simplifies expressions. Calcite has a
parameter for the simplify method which allows "unknown" expressions to
be treated as "unknown" or "false". For filters, we do want to treat
Unknowns
as False since a filter can only be true or false. However for expressions
in other parts of the code like select (e.g. select 1 in (NULL) ), the null
needs to be treated as "unknown" so that the simplify method can return null
for this expression.
Change-Id: I673162f253f983e0c95d01b1f8d2731881f9ad7b
Reviewed-on: http://gerrit.cloudera.org:8080/23951
Reviewed-by: Michael Smith <[email protected]>
Tested-by: Impala Public Jenkins <[email protected]>
---
.../apache/impala/calcite/operators/ImpalaRexSimplify.java | 14 ++++++++++----
.../impala/calcite/rules/ImpalaFilterSimplifyRule.java | 2 +-
.../functional-query/queries/QueryTest/calcite.test | 8 ++++++++
3 files changed, 19 insertions(+), 5 deletions(-)
diff --git
a/java/calcite-planner/src/main/java/org/apache/impala/calcite/operators/ImpalaRexSimplify.java
b/java/calcite-planner/src/main/java/org/apache/impala/calcite/operators/ImpalaRexSimplify.java
index 8260a93de..947131143 100644
---
a/java/calcite-planner/src/main/java/org/apache/impala/calcite/operators/ImpalaRexSimplify.java
+++
b/java/calcite-planner/src/main/java/org/apache/impala/calcite/operators/ImpalaRexSimplify.java
@@ -27,7 +27,6 @@ import org.apache.calcite.rex.RexUnknownAs;
import org.apache.calcite.sql.SqlBinaryOperator;
import org.apache.calcite.sql.type.SqlTypeUtil;
-
/**
* ImpalaRexSimplify extends the RexSimplify class in order to 'simplify'
expressions.
* The extension of the "simplify" method catches the double and float types
used in
@@ -50,9 +49,16 @@ public class ImpalaRexSimplify extends RexSimplify {
@Override
public RexNode simplify(RexNode rexNode) {
- return hasApproximateTypeIssues(rexNode)
- ? rexNode
- : super.simplifyUnknownAs(rexNode, RexUnknownAs.FALSE);
+ return simplify(rexNode, false);
+ }
+
+ public RexNode simplify(RexNode rexNode, boolean isFilter) {
+ if (hasApproximateTypeIssues(rexNode)) {
+ return rexNode;
+ }
+ return isFilter
+ ? super.simplifyUnknownAs(rexNode, RexUnknownAs.FALSE)
+ : super.simplify(rexNode);
}
private boolean hasApproximateTypeIssues(RexNode rexNode) {
diff --git
a/java/calcite-planner/src/main/java/org/apache/impala/calcite/rules/ImpalaFilterSimplifyRule.java
b/java/calcite-planner/src/main/java/org/apache/impala/calcite/rules/ImpalaFilterSimplifyRule.java
index 5ad9dbd22..8014fcc54 100644
---
a/java/calcite-planner/src/main/java/org/apache/impala/calcite/rules/ImpalaFilterSimplifyRule.java
+++
b/java/calcite-planner/src/main/java/org/apache/impala/calcite/rules/ImpalaFilterSimplifyRule.java
@@ -53,7 +53,7 @@ public class ImpalaFilterSimplifyRule extends RelOptRule {
RexNode condition = filter.getCondition();
RexExecutor executor = simplifier_.getRexExecutor();
- RexNode newCondition = simplifier_.simplify(condition);
+ RexNode newCondition = simplifier_.simplify(condition, true);
List<RexNode> reducedExprs = new ArrayList<>();
executor.reduce(rexBuilder, ImmutableList.of(newCondition), reducedExprs);
Preconditions.checkState(reducedExprs.size() == 1);
diff --git a/testdata/workloads/functional-query/queries/QueryTest/calcite.test
b/testdata/workloads/functional-query/queries/QueryTest/calcite.test
index c3f9adf14..7ed7c64eb 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/calcite.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/calcite.test
@@ -1239,3 +1239,11 @@ select count(*) from tpch.lineitem where l_quantity in
(1, 2)
---- RESULTS
239861
====
+---- QUERY
+# IMPALA-14525: Make sure null is treated as unknown in select clause
+SELECT 1 in (NULL);
+---- RESULTS
+NULL
+---- RUNTIME_PROFILE
+row_regex: .*PlannerType: CalcitePlanner.*
+====