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 8de13c5cc87 [fix](function) error scale set in unix_timestamp (#36110) 
(#37619)
8de13c5cc87 is described below

commit 8de13c5cc87761cf043b416249ec0687edd88929
Author: Mryange <[email protected]>
AuthorDate: Mon Jul 15 10:00:04 2024 +0800

    [fix](function) error scale set in unix_timestamp (#36110) (#37619)
    
    ## Proposed changes
    
    ```
    mysql [test]>set DEBUG_SKIP_FOLD_CONSTANT = true;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql [test]>select cast(unix_timestamp("2024-01-01",'yyyy-MM-dd') as 
bigint);
    +------------------------------------------------------------+
    | cast(unix_timestamp('2024-01-01', 'yyyy-MM-dd') as BIGINT) |
    +------------------------------------------------------------+
    |                                           1704038400000000 |
    +------------------------------------------------------------+
    ```
    now
    ```
    mysql [test]>select cast(unix_timestamp("2024-01-01",'yyyy-MM-dd') as 
bigint);
    +------------------------------------------------------------+
    | cast(unix_timestamp('2024-01-01', 'yyyy-MM-dd') as BIGINT) |
    +------------------------------------------------------------+
    |                                                 1704038400 |
    +------------------------------------------------------------+
    1 row in set (0.01 sec)
    ```
    
    The column does not have a scale set, but the cast uses the scale to
    perform the cast.
    
    
    <!--Describe your changes.-->
    
    ## Proposed changes
    
    Issue Number: close #xxx
    
    <!--Describe your changes.-->
---
 be/src/vec/functions/function_timestamp.cpp                            | 2 +-
 .../query_p0/sql_functions/datetime_functions/test_date_function.out   | 3 +++
 .../sql_functions/datetime_functions/test_date_function.groovy         | 2 ++
 3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/be/src/vec/functions/function_timestamp.cpp 
b/be/src/vec/functions/function_timestamp.cpp
index c2285795c71..483f8cf9928 100644
--- a/be/src/vec/functions/function_timestamp.cpp
+++ b/be/src/vec/functions/function_timestamp.cpp
@@ -831,7 +831,7 @@ struct UnixTimeStampStrImpl {
         std::tie(col_right, format_const) =
                 unpack_if_const(block.get_by_position(arguments[1]).column);
 
-        auto col_result = ColumnDecimal<Decimal64>::create(input_rows_count, 
0);
+        auto col_result = ColumnDecimal<Decimal64>::create(input_rows_count, 
6);
         auto null_map = ColumnVector<UInt8>::create(input_rows_count);
         auto& col_result_data = col_result->get_data();
         auto& null_map_data = null_map->get_data();
diff --git 
a/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
 
b/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
index ecf83359db8..c05fb8ef53e 100644
--- 
a/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
+++ 
b/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
@@ -380,6 +380,9 @@ February
 -- !sql_ustamp7 --
 1196389819.1235
 
+-- !sql_ustamp8 --
+1704038400
+
 -- !sql --
 0
 
diff --git 
a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
 
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
index 49db2bb4c80..fd504f0be9a 100644
--- 
a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
@@ -441,6 +441,7 @@ suite("test_date_function") {
     // UNIX_TIMESTAMP
     def unin_timestamp_str = """ select unix_timestamp() """
     assertTrue(unin_timestamp_str[0].size() == 1)
+
     qt_sql_ustamp1 """ select unix_timestamp('2007-11-30 10:30:19') """
     qt_sql_ustamp2 """ select unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d 
%H:%i-%s') """
     qt_sql_ustamp3 """ select unix_timestamp('2007-11-30 10:30%3A19', 
'%Y-%m-%d %H:%i%%3A%s') """
@@ -448,6 +449,7 @@ 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 cast(unix_timestamp("2024-01-01",'yyyy-MM-dd') 
as bigint) """
 
     // 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