From 749bd3078e241eefa4c78500f26ee8c3d92b9a08 Mon Sep 17 00:00:00 2001 From: zhangstar333 <87313068+zhangstar333@users.noreply.github.com> Date: Thu, 17 Oct 2024 20:16:02 +0800 Subject: [PATCH] [bug](function)fix date_floor function return wrong result (#41948) ``` void resize_fill(size_t n, const T& value) { size_t old_size = this->size(); if (n > old_size) { this->reserve(n); std::fill(t_end(), t_end() + n - old_size, value); } this->c_end = this->c_start + this->byte_size(n); } ``` if n is not greater than old_size, it's will not fill the data with value. so it's not set the null_map flag to 1, it's can't return NULL ``` mysql [test_query_qa]>select k11,hour_floor(k11,0) from baseall where k1 = 6; +---------------------+--------------------+ | k11 | hour_floor(k11, 0) | +---------------------+--------------------+ | 2015-03-13 12:36:38 | | +---------------------+--------------------+ 1 row in set (0.03 se ``` after fix: ``` mysql [test_query_qa]>select k11,hour_floor(k11,0) from baseall where k1 = 6; +---------------------+--------------------+ | k11 | hour_floor(k11, 0) | +---------------------+--------------------+ | 2015-03-13 12:36:38 | NULL | +---------------------+--------------------+ 1 row in set (0.03 sec) ``` --- be/src/vec/functions/function_datetime_floor_ceil.cpp | 9 ++++++--- regression-test/data/correctness_p0/test_time_round.out | 5 +++++ .../suites/correctness_p0/test_time_round.groovy | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/be/src/vec/functions/function_datetime_floor_ceil.cpp b/be/src/vec/functions/function_datetime_floor_ceil.cpp index 6cdfd01083d3c8..75cfd4e485f61c 100644 --- a/be/src/vec/functions/function_datetime_floor_ceil.cpp +++ b/be/src/vec/functions/function_datetime_floor_ceil.cpp @@ -21,6 +21,9 @@ #include #include +#include +#include +#include #include #include #include @@ -284,7 +287,7 @@ struct FloorCeilImpl { PaddedPODArray& res, NullMap& null_map) { // time_round(datetime,const(period)) if (period < 1) { - null_map.resize_fill(dates.size(), true); + memset(null_map.data(), 1, sizeof(UInt8) * dates.size()); return; } for (int i = 0; i < dates.size(); ++i) { @@ -325,7 +328,7 @@ struct FloorCeilImpl { NativeType origin_date, PaddedPODArray& res, NullMap& null_map) { if (period < 1) { - null_map.resize_fill(dates.size(), true); + memset(null_map.data(), 1, sizeof(UInt8) * dates.size()); return; } switch (period) { @@ -410,7 +413,7 @@ struct FloorCeilImpl { const PaddedPODArray& origin_dates, PaddedPODArray& res, NullMap& null_map) { if (period < 1) { - null_map.resize_fill(dates.size(), true); + memset(null_map.data(), 1, sizeof(UInt8) * dates.size()); return; } for (int i = 0; i < dates.size(); ++i) { diff --git a/regression-test/data/correctness_p0/test_time_round.out b/regression-test/data/correctness_p0/test_time_round.out index face63a18a9168..41e268482ed730 100644 --- a/regression-test/data/correctness_p0/test_time_round.out +++ b/regression-test/data/correctness_p0/test_time_round.out @@ -123,3 +123,8 @@ 2020-02-02T11:45:14 2020-02-02T11:45:14 +-- !select_1 -- +2020-02-02T13:09:20 \N +2020-02-02T13:09:20 \N +2020-02-02T13:09:20 \N + diff --git a/regression-test/suites/correctness_p0/test_time_round.groovy b/regression-test/suites/correctness_p0/test_time_round.groovy index c042e0dd935888..4ab6a6f6473058 100644 --- a/regression-test/suites/correctness_p0/test_time_round.groovy +++ b/regression-test/suites/correctness_p0/test_time_round.groovy @@ -89,4 +89,5 @@ suite("test_time_round") { qt_select "select hour_floor(dt,2,o) from dbround order by id;" qt_select "select hour_floor(dt,p,'1919-08-10 11:45:14') from dbround order by id;" qt_select "select hour_floor(dt,2,'1919-08-10 11:45:14') from dbround order by id;" + qt_select_1 "select dt,hour_floor(dt,0) from dbround order by id;" }