This is an automated email from the ASF dual-hosted git repository. zhangstar333 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 0056b11b2f8 [Bug](function) fix date_floor default value not 0001-01-01 00:00:00 (#50479) 0056b11b2f8 is described below commit 0056b11b2f8896b10f91b5e4980c11288e763db7 Author: HappenLee <happen...@selectdb.com> AuthorDate: Wed Apr 30 11:47:41 2025 +0800 [Bug](function) fix date_floor default value not 0001-01-01 00:00:00 (#50479) ### What problem does this PR solve? 1. fix FE and BE behavior different, when period lower than 1 2. fix the default start day different in BE/FE/Doc. now use `0001-01-01 00:00:00` union --- .../vec/functions/function_datetime_floor_ceil.cpp | 11 ++--------- be/src/vec/runtime/vdatetime_value.h | 11 ++--------- .../functions/executable/TimeRoundSeries.java | 7 +++++-- .../data/correctness_p0/test_time_round.out | Bin 5047 -> 5047 bytes .../data/nereids_function_p0/scalar_function/D.out | Bin 34248 -> 34248 bytes .../data/nereids_function_p0/scalar_function/H.out | Bin 17180 -> 17180 bytes .../data/nereids_function_p0/scalar_function/M.out | Bin 41160 -> 41160 bytes .../data/nereids_function_p0/scalar_function/S.out | Bin 53624 -> 53624 bytes .../data/nereids_function_p0/scalar_function/W.out | Bin 23595 -> 23595 bytes .../data/nereids_function_p0/scalar_function/Y.out | Bin 18467 -> 18467 bytes .../datetime_functions/test_date_floor_ceil.out | Bin 748 -> 886 bytes .../datetime_functions/test_date_floor_ceil.groovy | 13 ++++++++++++- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/be/src/vec/functions/function_datetime_floor_ceil.cpp b/be/src/vec/functions/function_datetime_floor_ceil.cpp index 7a00bf32590..0e5cd2f2f58 100644 --- a/be/src/vec/functions/function_datetime_floor_ceil.cpp +++ b/be/src/vec/functions/function_datetime_floor_ceil.cpp @@ -361,8 +361,7 @@ private: auto ts_arg = binary_cast<NativeType, DateValueType>(date); auto& ts_res = (DateValueType&)(res); if constexpr (Flag::Unit == WEEK) { - // Only week use the FIRST SUNDAY - ts_res = DateValueType::FIRST_SUNDAY; + ts_res = DateValueType::FIRST_DAY; return time_round_two_args(ts_arg, 1, ts_res); } else { return time_round_one_arg(ts_arg, ts_res); @@ -378,13 +377,7 @@ private: floor_opt(ts_arg, ts_res, period); return true; } else { - if constexpr (Flag::Unit == WEEK) { - ts_res = DateValueType::FIRST_SUNDAY; - } else { - // Only week use the FIRST SUNDAY - ts_res = DateValueType::FIRST_DAY; - } - + ts_res = DateValueType::FIRST_DAY; return time_round_two_args(ts_arg, period, ts_res); } } diff --git a/be/src/vec/runtime/vdatetime_value.h b/be/src/vec/runtime/vdatetime_value.h index 5d53ec64e47..77df894f21c 100644 --- a/be/src/vec/runtime/vdatetime_value.h +++ b/be/src/vec/runtime/vdatetime_value.h @@ -266,7 +266,6 @@ public: _year(0) {} // before int128 16 bytes ---> after int64 8 bytes const static VecDateTimeValue FIRST_DAY; - const static VecDateTimeValue FIRST_SUNDAY; // The data format of DATE/DATETIME is different in storage layer and execute layer. // So we should use different creator to get data from value. @@ -768,10 +767,7 @@ private: _year(year) {} }; -inline const VecDateTimeValue VecDateTimeValue::FIRST_DAY(false, TYPE_DATETIME, 0, 0, 0, 1970, 1, - 1); -inline const VecDateTimeValue VecDateTimeValue::FIRST_SUNDAY(false, TYPE_DATETIME, 0, 0, 0, 1970, 1, - 4); +inline const VecDateTimeValue VecDateTimeValue::FIRST_DAY(false, TYPE_DATETIME, 0, 0, 0, 1, 1, 1); template <typename T> class DateV2Value { @@ -792,7 +788,6 @@ public: DateV2Value(const DateV2Value<T>& other) = default; const static DateV2Value<T> FIRST_DAY; - const static DateV2Value<T> FIRST_SUNDAY; static DateV2Value create_from_olap_date(uint64_t value) { DateV2Value<T> date; @@ -1375,9 +1370,7 @@ private: }; template <typename T> -inline const DateV2Value<T> DateV2Value<T>::FIRST_DAY = DateV2Value<T>(1970, 1, 1, 0, 0, 0, 0); -template <typename T> -inline const DateV2Value<T> DateV2Value<T>::FIRST_SUNDAY = DateV2Value<T>(1970, 1, 4, 0, 0, 0, 0); +inline const DateV2Value<T> DateV2Value<T>::FIRST_DAY = DateV2Value<T>(1, 1, 1, 0, 0, 0, 0); // only support DATE - DATE (no support DATETIME - DATETIME) std::size_t operator-(const VecDateTimeValue& v1, const VecDateTimeValue& v2); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/TimeRoundSeries.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/TimeRoundSeries.java index 41254428322..8dd933a7a1a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/TimeRoundSeries.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/TimeRoundSeries.java @@ -33,8 +33,7 @@ import java.time.LocalDateTime; */ @Developing public class TimeRoundSeries { - private static final LocalDateTime START_ORIGINAL_DAY = LocalDateTime.of(1970, 1, 1, 0, 0, 0); - private static final LocalDateTime START_ORIGINAL_WEEK = LocalDateTime.of(1970, 1, 4, 0, 0, 0); + private static final LocalDateTime START_ORIGINAL_DAY = LocalDateTime.of(1, 1, 1, 0, 0, 0); enum DATE { YEAR, @@ -48,6 +47,10 @@ public class TimeRoundSeries { // get it's from be/src/vec/functions/function_datetime_floor_ceil.cpp##time_round private static LocalDateTime getDateCeilOrFloor(DATE tag, LocalDateTime date, int period, LocalDateTime origin, boolean getCeil) { + if (period < 1) { + return null; + } + DateTimeV2Literal dt = (DateTimeV2Literal) DateTimeV2Literal.fromJavaDateType(date); DateTimeV2Literal start = (DateTimeV2Literal) DateTimeV2Literal.fromJavaDateType(origin); long diff = 0; diff --git a/regression-test/data/correctness_p0/test_time_round.out b/regression-test/data/correctness_p0/test_time_round.out index 0cc936a7781..660e9680a85 100644 Binary files a/regression-test/data/correctness_p0/test_time_round.out and b/regression-test/data/correctness_p0/test_time_round.out differ diff --git a/regression-test/data/nereids_function_p0/scalar_function/D.out b/regression-test/data/nereids_function_p0/scalar_function/D.out index 93d3090d109..cc87f9917e2 100644 Binary files a/regression-test/data/nereids_function_p0/scalar_function/D.out and b/regression-test/data/nereids_function_p0/scalar_function/D.out differ diff --git a/regression-test/data/nereids_function_p0/scalar_function/H.out b/regression-test/data/nereids_function_p0/scalar_function/H.out index fa6e2caa7e4..37a991748da 100644 Binary files a/regression-test/data/nereids_function_p0/scalar_function/H.out and b/regression-test/data/nereids_function_p0/scalar_function/H.out differ diff --git a/regression-test/data/nereids_function_p0/scalar_function/M.out b/regression-test/data/nereids_function_p0/scalar_function/M.out index 2e71428c60d..02b99cffda4 100644 Binary files a/regression-test/data/nereids_function_p0/scalar_function/M.out and b/regression-test/data/nereids_function_p0/scalar_function/M.out differ diff --git a/regression-test/data/nereids_function_p0/scalar_function/S.out b/regression-test/data/nereids_function_p0/scalar_function/S.out index b346ae022a0..0aa14e84d2d 100644 Binary files a/regression-test/data/nereids_function_p0/scalar_function/S.out and b/regression-test/data/nereids_function_p0/scalar_function/S.out differ diff --git a/regression-test/data/nereids_function_p0/scalar_function/W.out b/regression-test/data/nereids_function_p0/scalar_function/W.out index 5a08c0727c8..89901daad5c 100644 Binary files a/regression-test/data/nereids_function_p0/scalar_function/W.out and b/regression-test/data/nereids_function_p0/scalar_function/W.out differ diff --git a/regression-test/data/nereids_function_p0/scalar_function/Y.out b/regression-test/data/nereids_function_p0/scalar_function/Y.out index 5daba3f64df..0e0fb57cdf6 100644 Binary files a/regression-test/data/nereids_function_p0/scalar_function/Y.out and b/regression-test/data/nereids_function_p0/scalar_function/Y.out differ diff --git a/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_floor_ceil.out b/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_floor_ceil.out index a7ef75b4442..22379a2b71b 100644 Binary files a/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_floor_ceil.out and b/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_floor_ceil.out differ diff --git a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_floor_ceil.groovy b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_floor_ceil.groovy index 8b15da2ad4b..ffcf9e5eb63 100644 --- a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_floor_ceil.groovy +++ b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_floor_ceil.groovy @@ -34,6 +34,17 @@ suite("test_date_floor_ceil") { qt_sql11 """select date_ceil("2023-07-14 10:51:00",interval 5 month); """ qt_sql12 """select date_ceil("2023-07-14 10:51:00",interval 5 year); """ + // test hour_floor + qt_sql1 """select hour_floor("2023-07-14 10:51:00", 5, "0001-01-01 00:00:00");""" + qt_sql2 """select hour_floor("2023-07-14 10:51:00", 5, "1970-01-01 00:00:00");""" + qt_sql3 """select hour_floor("2023-07-14 10:51:00", 5);""" + sql """set debug_skip_fold_constant = true""" + qt_sql1 """select hour_floor("2023-07-14 10:51:00", 5, "0001-01-01 00:00:00");""" + qt_sql2 """select hour_floor("2023-07-14 10:51:00", 5, "1970-01-01 00:00:00");""" + qt_sql3 """select hour_floor("2023-07-14 10:51:00", 5);""" + + + sql """set debug_skip_fold_constant = false""" qt_x1 """ select date_floor('9999-12-31 23:59:59.999999', interval 5 minute); """ qt_x2 """ select date_floor('9999-12-31 23:59:59.999999', interval 33333 year); """ qt_x3 """ select date_floor('9999-12-31 23:59:59.999999', interval -10 year); """ @@ -48,4 +59,4 @@ suite("test_date_floor_ceil") { qt_x12 """ select date_ceil('0001-09-01 23:59:59.999999', interval -7 month); """ qt_x13 """ select date_ceil('0002-02-01 23:59:59.999999', interval -7 month); """ qt_x14 """ select date_ceil('9999-12-31 23:54:59.999999', interval 5 minute); """ -} \ No newline at end of file +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org