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

gabriellee 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 dbd1dfb64c [Bug](date) fix BE crash if month_floor 's argument is null 
(#16281)
dbd1dfb64c is described below

commit dbd1dfb64c9deb0319be36fa3efbaecdecbb3af9
Author: Gabriel <[email protected]>
AuthorDate: Wed Feb 1 12:25:57 2023 +0800

    [Bug](date) fix BE crash if month_floor 's argument is null (#16281)
---
 be/src/vec/functions/function_datetime_floor_ceil.cpp     |  9 ++++++++-
 .../data/nereids_function_p0/scalar_function/L-Q.out      | 15 +++++++++++++++
 .../suites/nereids_function_p0/scalar_function/L-Q.groovy |  2 +-
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/be/src/vec/functions/function_datetime_floor_ceil.cpp 
b/be/src/vec/functions/function_datetime_floor_ceil.cpp
index 8555aa8986..70ba43784d 100644
--- a/be/src/vec/functions/function_datetime_floor_ceil.cpp
+++ b/be/src/vec/functions/function_datetime_floor_ceil.cpp
@@ -434,13 +434,20 @@ struct TimeRound {
         res = origin_date;
         auto ts2 = binary_cast<NativeType, DateValueType>(date);
         auto& ts1 = (DateValueType&)(res);
-
+        if (!ts2.is_valid_date() || !ts1.is_valid_date()) {
+            is_null = true;
+            return;
+        }
         TimeRound<Impl>::template time_round<NativeType, DateValueType>(ts2, 
period, ts1, is_null);
     }
 
     template <typename NativeType, typename DateValueType>
     static void time_round(NativeType date, Int32 period, NativeType& res, 
UInt8& is_null) {
         auto ts2 = binary_cast<NativeType, DateValueType>(date);
+        if (!ts2.is_valid_date()) {
+            is_null = true;
+            return;
+        }
         auto& ts1 = (DateValueType&)(res);
         if constexpr (Impl::Unit != WEEK) {
             ts1.from_olap_datetime(FIRST_DAY);
diff --git a/regression-test/data/nereids_function_p0/scalar_function/L-Q.out 
b/regression-test/data/nereids_function_p0/scalar_function/L-Q.out
index c0e8936e2f..84f7274194 100644
--- a/regression-test/data/nereids_function_p0/scalar_function/L-Q.out
+++ b/regression-test/data/nereids_function_p0/scalar_function/L-Q.out
@@ -1304,6 +1304,21 @@ dc5f80c371451aa4fc81c930adc64f60
 2012-03-01T00:00
 2012-03-01T00:00
 
+-- !sql --
+\N
+2012-03-01T00:00
+2012-03-01T00:00
+2012-03-01T00:00
+2012-03-01T00:00
+2012-03-01T00:00
+2012-03-01T00:00
+2012-03-01T00:00
+2012-03-01T00:00
+2012-03-01T00:00
+2012-03-01T00:00
+2012-03-01T00:00
+2012-03-01T00:00
+
 -- !sql --
 \N
 2012-03-01
diff --git 
a/regression-test/suites/nereids_function_p0/scalar_function/L-Q.groovy 
b/regression-test/suites/nereids_function_p0/scalar_function/L-Q.groovy
index c908f94a34..fbd2cddf2d 100644
--- a/regression-test/suites/nereids_function_p0/scalar_function/L-Q.groovy
+++ b/regression-test/suites/nereids_function_p0/scalar_function/L-Q.groovy
@@ -150,7 +150,7 @@ suite("nereids_scalar_fn_3") {
     qt_sql "select month_ceil(kdtmv2s1, kint, kdtmv2s1) from fn_test order by 
kdtmv2s1, kint, kdtmv2s1"
     qt_sql "select month_ceil(kdtv2, kint, kdtv2) from fn_test order by kdtv2, 
kint, kdtv2"
     // core
-    // qt_sql "select month_floor(kdtm) from fn_test order by kdtm"
+    qt_sql "select month_floor(kdtm) from fn_test order by kdtm"
     qt_sql "select month_floor(kdtmv2s1) from fn_test order by kdtmv2s1"
     qt_sql "select month_floor(kdtv2) from fn_test order by kdtv2"
     qt_sql "select month_floor(kdtm, kdtm) from fn_test order by kdtm, kdtm"


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

Reply via email to