Skip to content

Commit

Permalink
[bug](function) fix width bucket function return wrong result
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangstar333 committed Sep 20, 2023
1 parent 5a0ccd7 commit 899c245
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions be/src/vec/functions/function_width_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class FunctionWidthBucket : public IFunction {
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) {
Expand All @@ -107,8 +108,8 @@ class FunctionWidthBucket : public IFunction {
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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

0 comments on commit 899c245

Please sign in to comment.