This is an automated email from the ASF dual-hosted git repository. dataroaring pushed a commit to branch branch-3.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push: new 53782c71fe9 branch-3.0: [fix](nereids) fix to_monday('1970-01-04 23:59:59') #49153 (#49175) 53782c71fe9 is described below commit 53782c71fe944833f2f8c60c7a4e8d0a87c3aab6 Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> AuthorDate: Thu Mar 20 14:51:24 2025 +0800 branch-3.0: [fix](nereids) fix to_monday('1970-01-04 23:59:59') #49153 (#49175) Cherry-picked from #49153 Co-authored-by: yujun <yu...@selectdb.com> --- .../executable/DateTimeExtractAndTransform.java | 2 +- .../nereids_syntax_p0/test_cast_datetime.groovy | 29 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java index bd1915c2d82..763cc492ef6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java @@ -463,7 +463,7 @@ public class DateTimeExtractAndTransform { } private static LocalDateTime toMonday(LocalDateTime dateTime) { - LocalDateTime specialUpperBound = LocalDateTime.of(1970, 1, 4, 0, 0, 0); + LocalDateTime specialUpperBound = LocalDateTime.of(1970, 1, 4, 23, 59, 59, 999_999_999); LocalDateTime specialLowerBound = LocalDateTime.of(1970, 1, 1, 0, 0, 0); if (dateTime.isAfter(specialUpperBound) || dateTime.isBefore(specialLowerBound)) { return dateTime.plusDays(-dateTime.getDayOfWeek().getValue() + 1); diff --git a/regression-test/suites/nereids_syntax_p0/test_cast_datetime.groovy b/regression-test/suites/nereids_syntax_p0/test_cast_datetime.groovy index 5ffddd853bf..32eb0da90eb 100644 --- a/regression-test/suites/nereids_syntax_p0/test_cast_datetime.groovy +++ b/regression-test/suites/nereids_syntax_p0/test_cast_datetime.groovy @@ -460,6 +460,34 @@ suite("test_cast_datetime") { result([[Date.valueOf('1970-01-01')]]) } + test { + sql "select to_monday('1969-12-31')" + result([[Date.valueOf('1969-12-29')]]) + } + + test { + sql "select to_monday('1969-12-31 23:59:59.999999')" + result([[Date.valueOf('1969-12-29')]]) + } + + // to_monday(1970-01-01 ~ 170-01-04) will return 1970-01-01 + for (def s : ['1970-01-01', '1970-01-01 00:00:00.000001', '1970-01-02 12:00:00', '1970-01-01', '1970-01-04 23:59:59.999999']) { + test { + sql "select to_monday('${s}')" + result([[Date.valueOf('1970-01-01')]]) + } + } + + test { + sql "select to_monday('1970-01-05')" + result([[Date.valueOf('1970-01-05')]]) + } + + test { + sql "select to_monday('1970-01-05 00:00:00.000001')" + result([[Date.valueOf('1970-01-05')]]) + } + test { sql "select cast('123.123' as datetime)" result([[LocalDateTime.parse('2012-03-12T03:00:00')]]) @@ -544,6 +572,5 @@ suite("test_cast_datetime") { sql "select date_add('2023-11-05 01:30:00 America/New_York', INTERVAL 1 DAY)" result([[LocalDateTime.parse('2023-11-06T01:30:00')]]) } - } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org