From dbd1dfb64c9deb0319be36fa3efbaecdecbb3af9 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Wed, 1 Feb 2023 12:25:57 +0800 Subject: [PATCH] [Bug](date) fix BE crash if month_floor 's argument is null (#16281) --- .../functions/function_datetime_floor_ceil.cpp | 9 ++++++++- .../nereids_function_p0/scalar_function/L-Q.out | 15 +++++++++++++++ .../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(date); auto& ts1 = (DateValueType&)(res); - + if (!ts2.is_valid_date() || !ts1.is_valid_date()) { + is_null = true; + return; + } TimeRound::template time_round(ts2, period, ts1, is_null); } template static void time_round(NativeType date, Int32 period, NativeType& res, UInt8& is_null) { auto ts2 = binary_cast(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"