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 d667b5af385 [branch-2.1](function) Fix unexpected result of 
unix_timestamp when input is out of bound (#49430) (#50609)
d667b5af385 is described below

commit d667b5af385c729a5d634fbc25936d73ba550c72
Author: zclllyybb <[email protected]>
AuthorDate: Tue May 6 17:10:55 2025 +0800

    [branch-2.1](function) Fix unexpected result of unix_timestamp when input 
is out of bound (#49430) (#50609)
    
    pick https://github.com/apache/doris/pull/49430 but removed be-ut
    because we can't.
    
    Co-authored-by: Pxl <[email protected]>
---
 be/src/vec/functions/function_timestamp.cpp         |   3 +--
 .../datetime_functions/test_date_function.out       | Bin 10015 -> 10112 bytes
 .../datetime_functions/test_date_function.groovy    |   4 ++++
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/be/src/vec/functions/function_timestamp.cpp 
b/be/src/vec/functions/function_timestamp.cpp
index c1bb2d51397..2a6295e9d64 100644
--- a/be/src/vec/functions/function_timestamp.cpp
+++ b/be/src/vec/functions/function_timestamp.cpp
@@ -673,8 +673,7 @@ struct UnixTimeStampDateImpl {
                         ts_value.unix_timestamp(&timestamp, 
context->state()->timezone_obj());
                 DCHECK(valid);
 
-                auto& [sec, ms] = timestamp;
-                sec = UnixTimeStampImpl::trim_timestamp(sec);
+                auto [sec, ms] = UnixTimeStampImpl::trim_timestamp(timestamp);
                 auto ms_str = std::to_string(ms).substr(0, scale);
                 if (ms_str.empty()) {
                     ms_str = "0";
diff --git 
a/regression-test/data/nereids_p0/sql_functions/datetime_functions/test_date_function.out
 
b/regression-test/data/nereids_p0/sql_functions/datetime_functions/test_date_function.out
index fe77b8ffdb6..ed8c4fb35c5 100644
Binary files 
a/regression-test/data/nereids_p0/sql_functions/datetime_functions/test_date_function.out
 and 
b/regression-test/data/nereids_p0/sql_functions/datetime_functions/test_date_function.out
 differ
diff --git 
a/regression-test/suites/nereids_p0/sql_functions/datetime_functions/test_date_function.groovy
 
b/regression-test/suites/nereids_p0/sql_functions/datetime_functions/test_date_function.groovy
index 7e115693d27..0fffdec435a 100644
--- 
a/regression-test/suites/nereids_p0/sql_functions/datetime_functions/test_date_function.groovy
+++ 
b/regression-test/suites/nereids_p0/sql_functions/datetime_functions/test_date_function.groovy
@@ -382,6 +382,10 @@ suite("test_date_function") {
     qt_sql_ustamp5 """ select unix_timestamp('2007-11-30 10:30:19.123456') """
     qt_sql_ustamp6 """ select unix_timestamp(cast('2007-11-30 10:30:19.123456' 
as datetimev2(3))) """
     qt_sql_ustamp7 """ select unix_timestamp(cast('2007-11-30 10:30:19.123456' 
as datetimev2(4))) """
+    qt_sql_ustamp8 """ SELECT UNIX_TIMESTAMP('9999-12-30 23:59:59.999'); """
+    qt_sql_ustamp9 """ SELECT UNIX_TIMESTAMP('9999-12-30 23:59:59'); """
+    testFoldConst("SELECT UNIX_TIMESTAMP('9999-12-30 23:59:59.999');")
+    testFoldConst("SELECT UNIX_TIMESTAMP('9999-12-30 23:59:59');")
 
     // UTC_TIMESTAMP
     def utc_timestamp_str = sql """ select utc_timestamp(),utc_timestamp() + 1 
"""


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

Reply via email to