微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

bitmap sql的写法太麻烦,如何简化

如何解决bitmap sql的写法太麻烦,如何简化

这是一个物化视图database.table_tag_view,列是:

    tag_cate String,tag1     String,user_id_bit AggregateFunction(groupBitmap,UInt32)

tag_cate用户属性类型,如城市、年龄、学历、婚姻等; 列 tag_id 表示相应属性的值。

如果要统计满足以下条件的人数,我的sql如下:

condition:city in ('London','Beijing') and age in ('21-30','31-40') and education in ('master','doctor') and marriage ='Y' 

    select bitmapAndCardinality(
    (select bitmapAnd(
    (select bitmapAnd(
    (select groupBitmapOrState(user_id_bit)
    from database.table_tag_view 
    where tag_cate = 'city' and tag_id in ('London','Beijing')),(select groupBitmapOrState(user_id_bit)
    from database.table_tag_view 
    where tag_cate = 'age' and tag_id in ('21-30','31-40'))
    )),(select groupBitmapOrState(user_id_bit)
    from database.table_tag_view 
    where tag_cate = 'education' and tag_id in ('master','doctor'))
    )),(select groupBitmapOrState(user_id_bit)
    from database.table_tag_view 
    where tag_cate = 'marriage' and tag_id in ('Y')));

如果我要添加更多的条件,那么我会继续添加很多bitmapAnd语句,整个sql会很长而且不灵活。

这不是我想写的方式,我想写的方式是这样的:

    select bitmapCount(condition A & (condition B | condition C))
    from database.table_tag_view;

这能实现吗? 谢谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。