This is an automated email from the ASF dual-hosted git repository.
starocean999 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 8d6d952fe7c [fix](nereids) fix to_monday('1970-01-04 23:59:59')
(#49153)
8d6d952fe7c is described below
commit 8d6d952fe7cdf7c1fd7604394b33b22b50445256
Author: yujun <[email protected]>
AuthorDate: Tue Mar 18 09:54:37 2025 +0800
[fix](nereids) fix to_monday('1970-01-04 23:59:59') (#49153)
As doc
[to-monday](https://doris.apache.org/docs/2.0/sql-manual/sql-functions/date-time-functions/to-monday)
said, for date between 1970-01-01 and 1970-01-04, to_monday(date) =
'1970-01-01', this PR fix this.
---
.../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 e5036730822..4d4a1932d49 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: [email protected]
For additional commands, e-mail: [email protected]