This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit d918886e50085d2359f38b5404bb2469132dd76c
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 486e14ac72..d2cb8ce442 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
@@ -417,7 +417,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]

Reply via email to