This is an automated email from the ASF dual-hosted git repository. lihaopeng pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 294062d519 [bug](function) fix width bucket function return wrong result (#24673) 294062d519 is described below commit 294062d519f2655d654bf56347f12a1824ce4836 Author: zhangstar333 <87313068+zhangstar...@users.noreply.github.com> AuthorDate: Wed Sep 20 20:37:22 2023 +0800 [bug](function) fix width bucket function return wrong result (#24673) --- be/src/vec/functions/function_width_bucket.cpp | 5 +++-- .../width_bucket_fuctions/test_width_bucket_function.out | 15 +++++++++++++++ .../test_width_bucket_function.groovy | 6 ++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/be/src/vec/functions/function_width_bucket.cpp b/be/src/vec/functions/function_width_bucket.cpp index 42ad8156ed..cf93e2c8e5 100644 --- a/be/src/vec/functions/function_width_bucket.cpp +++ b/be/src/vec/functions/function_width_bucket.cpp @@ -98,6 +98,7 @@ private: for (size_t i = 0; i < input_rows_count; ++i) { auto min_value = min_value_column_concrete.get_data()[i]; auto max_value = max_value_column_concrete.get_data()[i]; + auto average_value = (max_value - min_value) / (1.0 * num_buckets); if (expr_column_concrete.get_data()[i] < min_value) { continue; } else if (expr_column_concrete.get_data()[i] >= max_value) { @@ -107,8 +108,8 @@ private: continue; } nested_column_concrete.get_data()[i] = - (int64_t)(1 + (expr_column_concrete.get_data()[i] - min_value) / - ((max_value - min_value) / num_buckets)); + (int64_t)(1 + + (expr_column_concrete.get_data()[i] - min_value) / average_value); } } } diff --git a/regression-test/data/query_p0/sql_functions/width_bucket_fuctions/test_width_bucket_function.out b/regression-test/data/query_p0/sql_functions/width_bucket_fuctions/test_width_bucket_function.out index 6f2348ac3e..bf7294504b 100644 --- a/regression-test/data/query_p0/sql_functions/width_bucket_fuctions/test_width_bucket_function.out +++ b/regression-test/data/query_p0/sql_functions/width_bucket_fuctions/test_width_bucket_function.out @@ -93,3 +93,18 @@ 7 5 8 \N +-- !select_width_bucket_1 -- +10 + +-- !select_width_bucket_2 -- +10 + +-- !select_width_bucket_3 -- +10 + +-- !select_width_bucket_4 -- +10 + +-- !select_width_bucket_5 -- +10 + diff --git a/regression-test/suites/query_p0/sql_functions/width_bucket_fuctions/test_width_bucket_function.groovy b/regression-test/suites/query_p0/sql_functions/width_bucket_fuctions/test_width_bucket_function.groovy index dca36cb1da..7ed23d697e 100644 --- a/regression-test/suites/query_p0/sql_functions/width_bucket_fuctions/test_width_bucket_function.groovy +++ b/regression-test/suites/query_p0/sql_functions/width_bucket_fuctions/test_width_bucket_function.groovy @@ -83,4 +83,10 @@ suite("test_width_bucket_function") { qt_select "SELECT k1, width_bucket(v1, date('2023-11-18'), date('2027-11-18'), 4) FROM ${tableName2} ORDER BY k1" qt_select "SELECT k1, width_bucket(v2, 200000, 600000, 4) FROM ${tableName2} ORDER BY k1" qt_select "SELECT k1, width_bucket(v3, 200000, 600000, 4) FROM ${tableName2} ORDER BY k1" + + qt_select_width_bucket_1 "select width_bucket(10,0,11,10);" + qt_select_width_bucket_2 "select width_bucket(cast(10 as int),0,11,10);" + qt_select_width_bucket_3 "select width_bucket(10.0,0,11,10);" + qt_select_width_bucket_4 "select width_bucket(10,0,10.1,10);" + qt_select_width_bucket_5 "select width_bucket(10,0,10.10,10);" } \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org