1. -- drop table user_tag_bitmap_local2
    2. CREATE TABLE user_tag_bitmap_local2
    3. (
    4. `tag` String,
    5. `tag_item` String,
    6. `p_day` Date,
    7. `origin_user` UInt64,
    8. `users` AggregateFunction(groupBitmap, UInt64)
    9. )
    10. ENGINE = AggregatingMergeTree
    11. PARTITION BY toYYYYMMDD(p_day)
    12. ORDER BY (tag, tag_item)
    13. SETTINGS index_granularity = 8192;
    14. -- 插入数据
    15. insert into user_tag_bitmap_local2 (tag,tag_item,p_day,origin_user,users)
    16. select 'sex', 'f', '2022-01-25', 2005, groupBitmapState(toUInt64(2005))
    17. select *,bitmapToArray(users) from user_tag_bitmap_local2
    18. SELECT bitmapToArray(users) FROM user_tag_bitmap_local2
    19. WHERE tag = 'sex' AND tag_item = 'm'
    20. -- 查找(合并)数据
    21. SELECT bitmapToArray(groupBitmapMergeState((users)))
    22. FROM user_tag_bitmap_local2 WHERE tag = 'sex' AND tag_item = 'f'
    23. -- 位运算
    24. WITH
    25. (
    26. SELECT groupBitmapMergeState(users)
    27. FROM user_tag_bitmap_local2
    28. WHERE tag_item = 'f'
    29. ) AS user_group_1,
    30. (
    31. SELECT groupBitmapMergeState(users)
    32. FROM user_tag_bitmap_local2
    33. WHERE tag_item = 'm'
    34. ) AS user_group_2
    35. SELECT bitmapToArray(bitmapAnd(user_group_1, user_group_2))