From 8de13c5cc87761cf043b416249ec0687edd88929 Mon Sep 17 00:00:00 2001 From: Mryange <59914473+Mryange@users.noreply.github.com> Date: Mon, 15 Jul 2024 10:00:04 +0800 Subject: [PATCH] [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. ## Proposed changes Issue Number: close #xxx --- be/src/vec/functions/function_timestamp.cpp | 2 +- .../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 c2285795c7..483f8cf992 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::create(input_rows_count, 0); + auto col_result = ColumnDecimal::create(input_rows_count, 6); auto null_map = ColumnVector::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 ecf83359db..c05fb8ef53 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 49db2bb4c8..fd504f0be9 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 """