BITMAP_INTERSECT
説明
集約関数で、グループ化後のビットマップの積集合を計算するために使用されます。ユーザー継続率の計算などの一般的な使用シナリオがあります。
構文
BITMAP_INTERSECT(BITMAP <value>)
パラメータ
| パラメータ | 説明 |
|---|---|
<value> | サポートされているビットマップデータ型 |
戻り値
戻り値のデータ型はBITMAPです。
例
-- setup
CREATE TABLE user_tags (
tag VARCHAR(20),
date DATETIME,
user_id BITMAP bitmap_union
) AGGREGATE KEY(tag, date) DISTRIBUTED BY HASH(tag) BUCKETS 1
PROPERTIES ("replication_num" = "1");
INSERT INTO user_tags VALUES
('A', '2020-05-18', to_bitmap(1)),
('A', '2020-05-18', to_bitmap(2)),
('A', '2020-05-19', to_bitmap(2)),
('A', '2020-05-19', to_bitmap(3)),
('B', '2020-05-18', to_bitmap(4)),
('B', '2020-05-19', to_bitmap(4)),
('B', '2020-05-19', to_bitmap(5));
テーブルスキーマ
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;
bitmap_to_string関数と組み合わせて使用し、交差の具体的なデータを取得する
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;