Skip to content

Commit

Permalink
[BugFix] fix handling of const column in array_to_bitmap (#52423)
Browse files Browse the repository at this point in the history
Signed-off-by: silverbullet233 <[email protected]>
(cherry picked from commit e0e71c2)
  • Loading branch information
silverbullet233 authored and mergify[bot] committed Oct 30, 2024
1 parent 4cd741a commit 21ace2c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions be/src/exprs/bitmap_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ StatusOr<ColumnPtr> BitmapFunctions::bitmap_to_array(FunctionContext* context, c
StatusOr<ColumnPtr> BitmapFunctions::array_to_bitmap(FunctionContext* context, const starrocks::Columns& columns) {
RETURN_IF_COLUMNS_ONLY_NULL(columns);
const constexpr LogicalType TYPE = TYPE_BIGINT;
size_t size = columns[0]->size();
size_t size = columns[0]->is_constant() ? 1 : columns[0]->size();
ColumnBuilder<TYPE_OBJECT> builder(size);

Column* data_column = ColumnHelper::get_data_column(columns[0].get());
Expand Down Expand Up @@ -440,7 +440,8 @@ StatusOr<ColumnPtr> BitmapFunctions::array_to_bitmap(FunctionContext* context, c
// append bitmap
builder.append(std::move(bitmap));
}
return builder.build(ColumnHelper::is_all_const(columns));
auto result = builder.build(false);
return columns[0]->is_constant() ? ConstColumn::create(std::move(result), columns[0]->size()) : result;
}

StatusOr<ColumnPtr> BitmapFunctions::bitmap_max(FunctionContext* context, const starrocks::Columns& columns) {
Expand Down
13 changes: 13 additions & 0 deletions test/sql/test_array_fn/R/test_array_fn
Original file line number Diff line number Diff line change
Expand Up @@ -3562,6 +3562,19 @@ select REVERSE( cast ('[40360,40361]' as array<int>));
-- result:
[40361,40360]
-- !result
select bitmap_to_string(array_to_bitmap( cast ('[40360,40361]' as array<int>))) from table(generate_series(1,10,1));
-- result:
40360,40361
40360,40361
40360,40361
40360,40361
40360,40361
40360,40361
40360,40361
40360,40361
40360,40361
40360,40361
-- !result
select array_contains( cast ('null' as array<int>), 40360);
-- result:
None
Expand Down
1 change: 1 addition & 0 deletions test/sql/test_array_fn/T/test_array_fn
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ select array_sum( cast ('[40360,40361]' as array<int>));
select array_to_bitmap( cast ('[40360,40361]' as array<int>));
select bitmap_to_array(array_to_bitmap(cast ('[40360,40361]' as array<int>)));
select REVERSE( cast ('[40360,40361]' as array<int>));
select bitmap_to_string(array_to_bitmap( cast ('[40360,40361]' as array<int>))) from table(generate_series(1,10,1));


select array_contains( cast ('null' as array<int>), 40360);
Expand Down

0 comments on commit 21ace2c

Please sign in to comment.