This is an automated email from the ASF dual-hosted git repository.

lijibing 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 e9d14da87cf branch-3.0: [fix](Nereids) fix unix_timestamp #49686 
(#50670)
e9d14da87cf is described below

commit e9d14da87cf56eda9a168f49951fa58259390387
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu May 8 10:01:07 2025 +0800

    branch-3.0: [fix](Nereids) fix unix_timestamp #49686 (#50670)
    
    Cherry-picked from #49686
    
    Co-authored-by: LiBinfeng <libinf...@selectdb.com>
---
 .../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 568740f9d35..aa45df5d1c8 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
@@ -607,14 +607,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 a78067259dd..5bd4084212e 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
@@ -78,4 +78,21 @@ suite("fold_constant_date_arithmatic") {
     testFoldConst("select next_day('2020-02-29', 'MON');") // 2020-03-02 (leap 
year to next month)
     testFoldConst("select next_day('2019-02-26', 'THU');") // 2019-02-28 
(non-leap year)
     testFoldConst("select next_day('2019-02-28', 'SUN');") // 2019-03-03 
(non-leap year to next month)
+    
+    // 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: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to