* Support bitmap_intersect
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.
* Add docs of bitmap_union and bitmap_intersect
* Support null of bitmap_intersect
2.0 KiB
2.0 KiB
title, language
| title | language |
|---|---|
| bitmap_intersect | en |
bitmap_intersect
description
Aggregation function, used to calculate the bitmap intersection after grouping. Common usage scenarios such as: calculating user retention rate.
Syntax
BITMAP BITMAP_INTERSECT(BITMAP value)
Enter a set of bitmap values, find the intersection of the set of bitmap values, and return.
example
Table schema
KeysType: AGG_KEY
Columns: tag varchar, date datetime, user_id bitmap bitmap_union
Find the retention of users between 2020-05-18 and 2020-05-19 under different tags.
mysql> select tag, bitmap_intersect(user_id) from (select tag, date, bitmap_union(user_id) user_id from table where date in ('2020-05-18', '2020-05-19') group by tag, date) a group by tag;
Used in combination with the bitmap_to_string function to obtain the specific data of the intersection
Who are the users retained under different tags between 2020-05-18 and 2020-05-19?
mysql> select tag, bitmap_to_string(bitmap_intersect(user_id)) from (select tag, date, bitmap_union(user_id) user_id from table where date in ('2020-05-18', '2020-05-19') group by tag, date) a group by tag;
keyword
BITMAP_INTERSECT, BITMAP