Skip to content

Conversation

@EmmyMiao87
Copy link
Contributor

Support aggregate function Bitmap Intersect, it is mainly used to take intersection of grouped data.
The function 'bitmap_intersect(expr)' calculates the intersection of bitmap columns and returns a bitmap object.
The defination is following:
FunctionName: bitmap_intersect,
InputType: bitmap,
OutputType: bitmap

The scenario is as follows:
Query which users satisfy the three tags a, b, and c at the same time.

select bitmap_to_string(bitmap_intersect(user_id)) from
(
    select bitmap_union(user_id) user_id from bitmap_intersect_test
    where tag in ('a', 'b', 'c')
    group by tag
) a

Closed #3552.

Change-Id: I0d50c9bb6827f7319c4d854f621412343a3ece24

Support aggregate function Bitmap Intersect, it is mainly used to take intersection of grouped data.
The function 'bitmap_intersect(expr)' calculates the intersection of bitmap columns and returns a bitmap object.
The defination is following:
FunctionName: bitmap_intersect,
InputType: bitmap,
OutputType: bitmap

The scenario is as follows:
Query which users satisfy the three tags a, b, and c at the same time.

```
select bitmap_to_string(bitmap_intersect(user_id)) from
(
    select bitmap_union(user_id) user_id from bitmap_intersect_test
    where tag in ('a', 'b', 'c')
    group by tag
) a
```
Closed apache#3552.

Change-Id: I0d50c9bb6827f7319c4d854f621412343a3ece24
@EmmyMiao87 EmmyMiao87 added kind/feature Categorizes issue or PR as related to a new feature. api-review Categorizes an issue or PR as actively needing an API review. area/sql/function Issues or PRs related to the SQL functions labels May 12, 2020
@EmmyMiao87 EmmyMiao87 self-assigned this May 12, 2020
@EmmyMiao87
Copy link
Contributor Author

I will add sql-reference later.

Co-authored-by: Mingyu Chen <morningman.cmy@gmail.com>
Change-Id: I4a815eaa5aac07ab75bb07e13f518da59cbef952
…bator-doris into bitmap_intersect

Change-Id: I2f5bee7dd9a14f687881af8038dbbff17b6b6590
Change-Id: Ibb9bdb236d4d850e3d732bb55c441b7f8b80abba
Change-Id: I8bd03f5344eafc89a7d617d10399c848006bf590
return;
}
// if dst is null, the src input is the first value
if (dst->is_null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would better add a UNLIKELY macros.


// this is the read init function for bitmap_intersect
void BitmapFunctions::bitmap_intersect_init_real(FunctionContext* ctx, StringVal* dst) {
dst->is_null = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why initial result bitmap as null? it seems that it will return empty bitmap when result bitmap is null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial result bitmap must be null. Otherwise, the intersection between dst and src will be empty.

@kangkaisen
Copy link
Contributor

@EmmyMiao87 Hi.
当前对于 bitmap_intersect null的处理是不合理的。

按照SQL标准,sum(null), min(null), max(null)结果为 null. count(null)为0.

所以 对于 bitmap_intersect,bitmap_union 返回bitmap的函数,输入全是null时,应该返回null,
对于 bitmap_intersect_count, bitmap_union_count 等返回count值的函数, 输入全是null时,应该返回0.

在之前最开始的时候,我认为所有hll,bitmap的函数都不需要返回null,对于输入是null,我们返回empty bitmap 或者empty hll 即可。(it's my fault...)

所以目前bitmap_init, bitmap_serialize, bitmap_finalize的实现都是not nullable的。
所以你这个PR,你应该实现新的函数 nullable_bitmap_int, nullable_bitmap_serialize。nullable_bitmap_serialize 中src是null, 应该返回null,而不是空的empty.

Change-Id: I2d86d48dd5f5e836696b3d44620de41943052ee6
Change-Id: Ic21f0d500f464cee5d51e54858a18c89d080631b
Copy link
Contributor

@imay imay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@kangkaisen kangkaisen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM

@kangpinghuang
Copy link
Contributor

LGTM, +1

Copy link
Contributor

@kangpinghuang kangpinghuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kangpinghuang kangpinghuang merged commit 0d66e6b into apache:master May 20, 2020
@EmmyMiao87 EmmyMiao87 mentioned this pull request Aug 17, 2020
eldenmoon pushed a commit to eldenmoon/incubator-doris that referenced this pull request Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-review Categorizes an issue or PR as actively needing an API review. area/sql/function Issues or PRs related to the SQL functions kind/feature Categorizes issue or PR as related to a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Bitmap Intersect

6 participants