Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](function) the bucket number arg of width_bucket should be a positive integer value #37892

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions be/src/vec/functions/function_width_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "vec/columns/column.h"
#include "vec/columns/column_vector.h"
#include "vec/columns/columns_number.h"
#include "vec/common/assert_cast.h"
#include "vec/core/block.h"
#include "vec/core/column_numbers.h"
#include "vec/core/column_with_type_and_name.h"
Expand Down Expand Up @@ -71,6 +72,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;

Expand All @@ -86,12 +93,10 @@ 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<const ColumnType&>(expr_column);
const ColumnType& min_value_column_concrete =
reinterpret_cast<const ColumnType&>(min_value_column);
const ColumnType& max_value_column_concrete =
reinterpret_cast<const ColumnType&>(max_value_column);
ColumnInt64& nested_column_concrete = reinterpret_cast<ColumnInt64&>(nested_column);
const auto& expr_column_concrete = assert_cast<const ColumnType&>(expr_column);
const auto& min_value_column_concrete = assert_cast<const ColumnType&>(min_value_column);
const auto& max_value_column_concrete = assert_cast<const ColumnType&>(max_value_column);
auto& nested_column_concrete = assert_cast<ColumnInt64&>(nested_column);

size_t input_rows_count = expr_column.size();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Loading