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 c6376673946 branch-2.1:[fix](Nereids) when considering timezone to 
unix_timestamp, the boundary condition should changed (#49686) (#50669)
c6376673946 is described below

commit c6376673946afc3c8dc790988c406fb06c3180fc
Author: James <[email protected]>
AuthorDate: Thu May 8 09:46:31 2025 +0800

    branch-2.1:[fix](Nereids) when considering timezone to unix_timestamp, the 
boundary condition should changed (#49686) (#50669)
    
    backport: https://github.com/apache/doris/pull/49686
    
    Co-authored-by: LiBinfeng <[email protected]>
---
 .../executable/DateTimeExtractAndTransform.java         |  8 +++++---
 .../fold_constant/fold_constant_date_arithmatic.groovy  | 17 +++++++++++++++++
 2 files changed, 22 insertions(+), 3 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 0be185d80f9..d99da4c7905 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
@@ -574,14 +574,16 @@ public class DateTimeExtractAndTransform {
     private static String getTimestamp(LocalDateTime dateTime) {
         LocalDateTime specialUpperBound = LocalDateTime.of(2038, 1, 19, 3, 14, 
7);
         LocalDateTime specialLowerBound = LocalDateTime.of(1970, 1, 1, 0, 0, 
0);
+        dateTime = dateTime.atZone(DateUtils.getTimeZone())
+                        
.toOffsetDateTime().atZoneSameInstant(ZoneId.of("UTC+0"))
+                        .toLocalDateTime();
         if (dateTime.isBefore(specialLowerBound) || 
dateTime.isAfter(specialUpperBound)) {
             return "0";
         }
         Duration duration = Duration.between(
                 specialLowerBound,
-                dateTime.atZone(DateUtils.getTimeZone())
-                        
.toOffsetDateTime().atZoneSameInstant(ZoneId.of("UTC+0"))
-                        .toLocalDateTime());
+                dateTime
+                );
         if (duration.getNano() == 0) {
             return String.valueOf(duration.getSeconds());
         } else {
diff --git 
a/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_date_arithmatic.groovy
 
b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_date_arithmatic.groovy
index ccd3547deef..3a370627bb1 100644
--- 
a/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_date_arithmatic.groovy
+++ 
b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_date_arithmatic.groovy
@@ -48,4 +48,21 @@ suite("fold_constant_date_arithmatic") {
     testFoldConst("select str_to_date('31/12/2020 23:59', '%d/%m/%Y %H:%i');")
     testFoldConst("select str_to_date('31/12/2020 11:59 PM', '%d/%m/%Y %h:%i 
%p');")
     testFoldConst("select str_to_date('20201231T235959', '%Y%m%dT%H%i%s');")
+    
+    // test unix_timestamp
+    testFoldConst("select unix_timestamp('2023/04/31');")
+    testFoldConst("select unix_timestamp('1970/01/01 00:00:00');")
+    testFoldConst("select unix_timestamp('1970-01-01T00:00:00');")
+    testFoldConst("select unix_timestamp('1970-01-01');")
+    testFoldConst("select unix_timestamp('31/Apr/2023','%d/%b/%Y');")
+    testFoldConst("select unix_timestamp('00-00-0000');")
+    testFoldConst("select unix_timestamp('3000/02/29','%Y/%m/%d');")
+    testFoldConst("select unix_timestamp('01.Jan.1970','%d.%b.%Y');")
+    testFoldConst("select unix_timestamp('0000-00-00 00:00:00');")
+    testFoldConst("select unix_timestamp();")
+    testFoldConst("select unix_timestamp('2021-02-29', '%Y-%m-%d');")
+    testFoldConst("select unix_timestamp('2023/04/31', '%Y/%m/%d');")
+    testFoldConst("select unix_timestamp('2023-04-31 12:00:00');")
+    testFoldConst("select unix_timestamp('1970-01-01','%Y-%m-%d');")
+    testFoldConst("select unix_timestamp('0');")
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to