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 902629adb6 [fix](planner) fix targetTypeDef NPE when value is null
(#18072)
902629adb6 is described below
commit 902629adb63ac289143b6242a8eb657b961bac37
Author: mch_ucchi <[email protected]>
AuthorDate: Mon Mar 27 17:29:14 2023 +0800
[fix](planner) fix targetTypeDef NPE when value is null (#18072)
sql like:
select * from (select *, null as top from v1)t where top = 5;
select * from (select *, null as top from v1)t where top is not null;
will cause NPE because targetTypeDef is null when value is null. Now we use
cast target type to the targetTypeDef.
---
.../src/main/java/org/apache/doris/analysis/CastExpr.java | 6 +++++-
.../suites/query_p0/literal_view/lietral_test.groovy | 15 +++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java
index ec3fda9eb1..a59f30039d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java
@@ -438,7 +438,11 @@ public class CastExpr extends Expr {
private Expr castTo(LiteralExpr value) throws AnalysisException {
if (value instanceof NullLiteral) {
- return NullLiteral.create(targetTypeDef.getType());
+ if (targetTypeDef != null) {
+ return NullLiteral.create(targetTypeDef.getType());
+ } else {
+ return NullLiteral.create(type);
+ }
} else if (type.isIntegerType()) {
return new IntLiteral(value.getLongValue(), type);
} else if (type.isLargeIntType()) {
diff --git a/regression-test/suites/query_p0/literal_view/lietral_test.groovy
b/regression-test/suites/query_p0/literal_view/lietral_test.groovy
index 0307b0fce8..0c5f8bcec0 100644
--- a/regression-test/suites/query_p0/literal_view/lietral_test.groovy
+++ b/regression-test/suites/query_p0/literal_view/lietral_test.groovy
@@ -116,4 +116,19 @@ suite("literal_view_test") {
) a
where name != '1234';
"""
+
+ test {
+ sql "select * from (select null as top) t where top is not null"
+ result ([])
+ }
+
+ test {
+ sql "select * from (select null as top) t where top is null"
+ result ([[null]])
+ }
+
+ test {
+ sql "select * from (select null as top) t where top = 5"
+ result ([])
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]