Files
doris/docs/zh-CN/sql-reference/sql-functions/bitmap-functions/bitmap_intersect.md
EmmyMiao87 0d66e6bd15 Support bitmap_intersect (#3571)
* 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
2020-05-20 21:12:02 +08:00

1.8 KiB

title, language
title language
bitmap_intersect zh-CN

bitmap_intersect

description

聚合函数,用于计算分组后的 bitmap 交集。常见使用场景如:计算用户留存率。

Syntax

BITMAP BITMAP_INTERSECT(BITMAP value)

输入一组 bitmap 值,求这一组 bitmap 值的交集,并返回。

example

表结构

KeysType: AGG_KEY
Columns: tag varchar, date datetime, user_id bitmap bitmap_union

求今天和昨天不同 tag 下的用户留存
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;

和 bitmap_to_string 函数组合使用可以获取交集的具体数据

求今天和昨天不同 tag 下留存的用户都是哪些
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