This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 68e593fbf1 [fix](nereids)(planner) case when should return NullLiteral
when all case result is NullLiteral (#20280)
68e593fbf1 is described below
commit 68e593fbf1912683f72aa7a009794f7f0e17622d
Author: starocean999 <[email protected]>
AuthorDate: Thu Jun 1 11:11:41 2023 +0800
[fix](nereids)(planner) case when should return NullLiteral when all case
result is NullLiteral (#20280)
---
.../java/org/apache/doris/analysis/CaseExpr.java | 5 +++++
.../rules/expression/rules/FoldConstantRuleOnFE.java | 8 +++++++-
.../string_functions/test_string_function_like.out | 4 ++++
.../test_string_function_like.groovy | 20 ++++++++++++++++++++
4 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CaseExpr.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CaseExpr.java
index fb6414a1e2..548ceb1f62 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CaseExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CaseExpr.java
@@ -311,6 +311,11 @@ public class CaseExpr extends Expr {
// but for current LiteralExpr.compareLiteral, `123`' won't be regard
as true
// the case which two values has different type left to be
public static Expr computeCaseExpr(CaseExpr expr) {
+ if (expr.getType() == Type.NULL) {
+ // if expr's type is NULL_TYPE, means all possible return values
are nulls
+ // it's safe to return null literal here
+ return new NullLiteral();
+ }
LiteralExpr caseExpr;
int startIndex = 0;
int endIndex = expr.getChildren().size();
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnFE.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnFE.java
index 7c60c8df79..55e86699a9 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnFE.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnFE.java
@@ -374,7 +374,13 @@ public class FoldConstantRuleOnFE extends
AbstractExpressionRewriteRule {
return defaultResult == null ? new
NullLiteral(caseWhen.getDataType()) : defaultResult;
}
if (defaultResult == null) {
- return new CaseWhen(whenClauses);
+ if (caseWhen.getDataType().isNullType()) {
+ // if caseWhen's type is NULL_TYPE, means all possible return
values are nulls
+ // it's safe to return null literal here
+ return new NullLiteral();
+ } else {
+ return new CaseWhen(whenClauses);
+ }
}
return new CaseWhen(whenClauses, defaultResult);
}
diff --git
a/regression-test/data/nereids_p0/sql_functions/string_functions/test_string_function_like.out
b/regression-test/data/nereids_p0/sql_functions/string_functions/test_string_function_like.out
index 0741f7c66a..9d03233513 100644
---
a/regression-test/data/nereids_p0/sql_functions/string_functions/test_string_function_like.out
+++
b/regression-test/data/nereids_p0/sql_functions/string_functions/test_string_function_like.out
@@ -124,3 +124,7 @@ bb
-- !sql --
+-- !sql --
+
+-- !sql --
+
diff --git
a/regression-test/suites/nereids_p0/sql_functions/string_functions/test_string_function_like.groovy
b/regression-test/suites/nereids_p0/sql_functions/string_functions/test_string_function_like.groovy
index 171ec3d27a..05ed019fdf 100644
---
a/regression-test/suites/nereids_p0/sql_functions/string_functions/test_string_function_like.groovy
+++
b/regression-test/suites/nereids_p0/sql_functions/string_functions/test_string_function_like.groovy
@@ -70,5 +70,25 @@ suite("test_string_function_like") {
CREATE TABLE test_string_function_like_t0 (c0 SMALLINT DEFAULT
"1") DISTRIBUTED BY HASH (c0) PROPERTIES ("replication_num" = "1");
"""
qt_sql "select CASE TRUE WHEN CASE FALSE WHEN ( c0 IS NULL) THEN TRUE END
THEN NULL WHEN (('') LIKE c0) THEN '1970-04-17 18:47:49' END from
test_string_function_like_t0;"
+
+ qt_sql """select
+ CASE TRUE WHEN
+ CASE FALSE
+ WHEN ( c0 IS NULL) THEN
+ TRUE
+ END THEN
+ NULL
+ END
+ FROM test_string_function_like_t0;"""
+ sql "SET enable_nereids_planner=false"
+ qt_sql """select
+ CASE TRUE WHEN
+ CASE FALSE
+ WHEN ( c0 IS NULL) THEN
+ TRUE
+ END THEN
+ NULL
+ END
+ FROM test_string_function_like_t0;"""
// sql "DROP TABLE ${tbName};"
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]