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

starocean999 pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 31f507268da [fix](nereids)prevent null pointer exception if datetime 
value overflows (#39676)
31f507268da is described below

commit 31f507268da2f1339b9fd42332b2b1f5d149c689
Author: starocean999 <[email protected]>
AuthorDate: Wed Aug 21 14:17:26 2024 +0800

    [fix](nereids)prevent null pointer exception if datetime value overflows 
(#39676)
    
    pick from master https://github.com/apache/doris/pull/39482
---
 .../rules/SimplifyComparisonPredicate.java         |  5 +--
 .../trees/expressions/literal/DateLiteral.java     |  2 +-
 .../datatype/test_datetime_overflow.groovy         | 36 ++++++++++++++++++++++
 3 files changed, 40 insertions(+), 3 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyComparisonPredicate.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyComparisonPredicate.java
index 4d99ad18469..9f719c73772 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyComparisonPredicate.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyComparisonPredicate.java
@@ -336,9 +336,10 @@ public class SimplifyComparisonPredicate extends 
AbstractExpressionRewriteRule {
     private Expression migrateToDateV2(DateTimeLiteral l, AdjustType type) {
         DateV2Literal d = new DateV2Literal(l.getYear(), l.getMonth(), 
l.getDay());
         if (type == AdjustType.UPPER && (l.getHour() != 0 || l.getMinute() != 
0 || l.getSecond() != 0)) {
-            d = ((DateV2Literal) d.plusDays(1));
+            return d.plusDays(1);
+        } else {
+            return d;
         }
-        return d;
     }
 
     private Expression migrateToDate(DateV2Literal l) {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java
index 410b2cc4c1f..fb3dc4e67bb 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java
@@ -326,7 +326,7 @@ public class DateLiteral extends Literal {
     }
 
     protected static boolean isDateOutOfRange(LocalDateTime dateTime) {
-        return dateTime.isBefore(START_OF_A_DAY) || 
dateTime.isAfter(END_OF_A_DAY);
+        return dateTime == null || dateTime.isBefore(START_OF_A_DAY) || 
dateTime.isAfter(END_OF_A_DAY);
     }
 
     private boolean checkDatetime(TemporalAccessor dateTime) {
diff --git 
a/regression-test/suites/nereids_p0/datatype/test_datetime_overflow.groovy 
b/regression-test/suites/nereids_p0/datatype/test_datetime_overflow.groovy
new file mode 100644
index 00000000000..27f7addbd26
--- /dev/null
+++ b/regression-test/suites/nereids_p0/datatype/test_datetime_overflow.groovy
@@ -0,0 +1,36 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_datetime_overflow") {
+    sql 'set enable_nereids_planner=true'
+    sql 'set enable_fallback_to_original_planner=false'
+    sql """drop table if exists datetime_overflow_t"""
+    sql """CREATE TABLE datetime_overflow_t (
+            `id` bigint NULL,
+            `c` datetime NULL,
+            `d` date NULL,
+            INDEX idx_c (`c`) USING INVERTED
+            ) ENGINE=OLAP
+            DUPLICATE KEY(`id`)
+            DISTRIBUTED BY RANDOM BUCKETS AUTO
+            PROPERTIES (
+            "replication_num" = "1"
+            );"""
+
+    sql """select * from datetime_overflow_t where d between "9999-12-31 
00:00:01" and "9999-12-31 10:00:01";"""
+    sql """select * from datetime_overflow_t where d > "9999-12-31 
00:00:01";"""
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to