This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 44b868de6b9 branch-2.1: [fix](nereids) fix to_monday('1970-01-04
23:59:59') #49153 (#49176)
44b868de6b9 is described below
commit 44b868de6b9d66a20a12cff49cf6c893f4accca6
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Tue Mar 18 18:07:26 2025 +0800
branch-2.1: [fix](nereids) fix to_monday('1970-01-04 23:59:59') #49153
(#49176)
Cherry-picked from #49153
Co-authored-by: yujun <[email protected]>
---
.../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 b313c6b01ee..0cf8e38fcbc 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]