From b115b362fb57744960c5efc8a59f5c724263f218 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Wed, 20 Jul 2022 20:17:41 +0800 Subject: [PATCH] [Bug] fix bug for function `unix_timestamp` (#11041) * [Bug] fix bug for function `unix_timestamp` --- be/src/vec/functions/function_timestamp.cpp | 8 +++++++- .../datetime_functions/test_date_function.out | 3 +++ .../datetime_functions/test_date_function.groovy | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/be/src/vec/functions/function_timestamp.cpp b/be/src/vec/functions/function_timestamp.cpp index 691714cb33..8a50953e85 100644 --- a/be/src/vec/functions/function_timestamp.cpp +++ b/be/src/vec/functions/function_timestamp.cpp @@ -206,7 +206,13 @@ struct UnixTimeStampImpl { const ColumnNumbers& arguments, size_t result, size_t input_rows_count) { auto col_result = ColumnVector::create(); - col_result->insert(context->impl()->state()->timestamp_ms() / 1000); + col_result->resize(input_rows_count); + // TODO: use a const column to store this value + auto& col_result_data = col_result->get_data(); + auto res_value = context->impl()->state()->timestamp_ms() / 1000; + for (int i = 0; i < input_rows_count; i++) { + col_result_data[i] = res_value; + } block.replace_by_position(result, std::move(col_result)); return Status::OK(); } diff --git a/regression-test/data/query/sql_functions/datetime_functions/test_date_function.out b/regression-test/data/query/sql_functions/datetime_functions/test_date_function.out index 25b2d58cb3..c02183d1c3 100644 --- a/regression-test/data/query/sql_functions/datetime_functions/test_date_function.out +++ b/regression-test/data/query/sql_functions/datetime_functions/test_date_function.out @@ -287,3 +287,6 @@ February -- !sql -- 202026 +-- !sql -- +200 + diff --git a/regression-test/suites/query/sql_functions/datetime_functions/test_date_function.groovy b/regression-test/suites/query/sql_functions/datetime_functions/test_date_function.groovy index b963ab7870..eada2080eb 100644 --- a/regression-test/suites/query/sql_functions/datetime_functions/test_date_function.groovy +++ b/regression-test/suites/query/sql_functions/datetime_functions/test_date_function.groovy @@ -250,5 +250,7 @@ suite("test_date_function", "query") { qt_sql """ select yearweek('2021-1-1') """ qt_sql """ select yearweek('2020-7-1') """ + qt_sql """ select count(*) from (select * from numbers("200")) tmp1 WHERE 0 <= UNIX_TIMESTAMP(); """ + sql """ drop table ${tableName} """ }