hive grouping sets 和 cube 用法,hivegrouping


  • grouping sets 和cube基本知识。

    基础知识可参考 http://blog.csdn.net/mashroomxl/article/details/22578471

    grouping sets 适用于多维度统计,可以代替之前lateral view explode 方式

    cube 相当于grouping sets 所有条件组合。

    平时跑临时需求看数据,也可以用cube。比如看某款游戏android,ios,_NONE的数量,很方便可以用一个sql写。

  • grouping sets 与lateral view explode方式比较

    结论:map和reducer数一样,在运算速度上差距也不大,但写法会比较简单。

  • cube 使用碰到的情况

    当>=5个维度且聚合中用了distinct,会报如下错误

    An additional MR job is introduced since the cardinality of grouping sets is more than hive.new.job.grouping.set.cardinality.
    This functionality is not supported with distincts.
    Either set hive.new.job.grouping.set.cardinality to a high number (higher than the number of rows per input row due to grouping sets in the query),
    or rewrite the query to not use distincts. The number of rows per input row due to grouping sets is 32 (state=42000,code=10226)

    解决方法:如错误日志描述给出的解决方法,可以通过修改 hive.new.job.grouping.set.cardinality 配置,或者在聚合中不用distinct来解决。

    目前我们采用后者这个方式,可以通过在子查询中用group by去重,避免在聚合中用到distinct。

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关内容