From d667b5af385c729a5d634fbc25936d73ba550c72 Mon Sep 17 00:00:00 2001 From: zclllyybb Date: Tue, 6 May 2025 17:10:55 +0800 Subject: [PATCH] [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 --- be/src/vec/functions/function_timestamp.cpp | 3 +-- .../datetime_functions/test_date_function.out | 20 ++++++++++++------- .../test_date_function.groovy | 4 ++++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/be/src/vec/functions/function_timestamp.cpp b/be/src/vec/functions/function_timestamp.cpp index c1bb2d5139..2a6295e9d6 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(×tamp, 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 fe77b8ffdb..ed8c4fb35c 100644 --- 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 @@ -346,10 +346,10 @@ February 1196389819 -- !sql_ustamp2 -- -1196389819 +1196389819.000000 -- !sql_ustamp3 -- -1196389819 +1196389819.000000 -- !sql_ustamp4 -- 0 @@ -363,6 +363,12 @@ February -- !sql_ustamp7 -- 1196389819.1235 +-- !sql_ustamp8 -- +0.000 + +-- !sql_ustamp9 -- +0 + -- !sql -- 0 @@ -664,11 +670,11 @@ true 2023-08-17T17:41:18 -- !sql_dt_null_1 -- -1607702400.0000 1607702400 1607702400 1607702400 1607702400 -1607746332.0000 1607746332 1607702400 1607702400 1607746332 -1607746332.0000 1607746332 1607702400 1607702400 1607746332 -1607746332.1230 1607746332 1607702400 1607702400 1607746332 -1607746332.6667 1607746333 1607702400 1607702400 1607746333 +1607702400.0000 1607702400 1607702400 1607702400 1607702400.000000 +1607746332.0000 1607746332 1607702400 1607702400 1607746332.000000 +1607746332.0000 1607746332 1607702400 1607702400 1607746332.000000 +1607746332.1230 1607746332 1607702400 1607702400 1607746332.123000 +1607746332.6667 1607746333 1607702400 1607702400 1607746332.666666 -- !sql_time_value -- 1 00:00:00 0 0 0 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 7e115693d2..0fffdec435 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 """