[Bug](date) fix BE crash if month_floor 's argument is null (#16281)

This commit is contained in:
Gabriel
2023-02-01 12:25:57 +08:00
committed by GitHub
parent 95d7c2de26
commit dbd1dfb64c
3 changed files with 24 additions and 2 deletions

View File

@ -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);

View File

@ -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

View File

@ -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"