From 9349284e1f6dc60e97953a132ea0576afc5f1b0c Mon Sep 17 00:00:00 2001 From: Jerry Hu Date: Tue, 16 Jul 2024 14:52:36 +0800 Subject: [PATCH] [fix](function) the bucket number arg of width_bucket should be a positive integer value --- be/src/vec/functions/function_width_bucket.cpp | 14 ++++++++++---- .../test_width_bucket_function.groovy | 5 +++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/be/src/vec/functions/function_width_bucket.cpp b/be/src/vec/functions/function_width_bucket.cpp index 193cf832b1ad800..1ff90f95dae683d 100644 --- a/be/src/vec/functions/function_width_bucket.cpp +++ b/be/src/vec/functions/function_width_bucket.cpp @@ -71,6 +71,12 @@ class FunctionWidthBucket : public IFunction { block.get_by_position(arguments[3]).column->convert_to_full_column_if_const(); int64_t num_buckets = num_buckets_ptr->get_int(0); + if (num_buckets <= 0) { + return Status::InternalError( + "The desired number({}) of buckets must be a positive integer value.", + num_buckets); + } + auto nested_column_ptr = ColumnInt64::create(input_rows_count, 0); DataTypePtr expr_type = block.get_by_position(arguments[0]).type; @@ -86,12 +92,12 @@ class FunctionWidthBucket : public IFunction { void _execute(const IColumn& expr_column, const IColumn& min_value_column, const IColumn& max_value_column, const int64_t num_buckets, IColumn& nested_column) const { - const ColumnType& expr_column_concrete = reinterpret_cast(expr_column); - const ColumnType& min_value_column_concrete = + const auto& expr_column_concrete = reinterpret_cast(expr_column); + const auto& min_value_column_concrete = reinterpret_cast(min_value_column); - const ColumnType& max_value_column_concrete = + const auto& max_value_column_concrete = reinterpret_cast(max_value_column); - ColumnInt64& nested_column_concrete = reinterpret_cast(nested_column); + auto& nested_column_concrete = reinterpret_cast(nested_column); size_t input_rows_count = expr_column.size(); 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 c417671e4de0a1a..1a455da92446f8c 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 @@ -89,4 +89,9 @@ suite("test_width_bucket_function", "arrow_flight_sql") { 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);" + + test { + sql "select width_bucket(4, 0, 8, 0)" + exception "buckets must be a positive integer value" + } } \ No newline at end of file