有多条hive语句从同一张表中做count操作,语句如下:
select pf,way,method,count(distinct id) where push_date_type ='$push_date_type' group by pf,way,method;
select pf,way,-1,count(distinct id) where push_date_type ='$push_date_type' group by pf,way;
......
想着用multi group by特性优化下效率,于是把上述语句改写成:
from push_revisit_info insert overwrite table push_rpt_pf_way_mthd select pf,way,method,count(distinct id) where push_date_type ='$push_date_type' group by pf,way,method insert overwrite table push_rpt_pf_way select pf,way,-1,count(distinct id) where push_date_type ='$push_date_type' group by pf,way
参数hive.multigroupby.singlemr也设置成了true;
可是这条语句还是会生成两个mapreduce执行,跟未使用multi group by时MR Job数量一样,甚至执行时间还稍长。
如果这两句的group key用成一样,就会只生成一个MR Job,但不论hive.multigroupby.singlemr是true还是false,都是这样。
关于这个参数的含义,hive-default.xml是这样写的:
<property>
<name>hive.multigroupby.singlemr</name>
<value>false</value>
<description>Whether to optimize multi group by query to generate single M/R
job plan. If the multi group by query has common group by keys, it will be
optimized to generate single M/R job.</description>
</property>
这里的common翻译成什么最合适呢?“共同的”?那依上面的经验,不用开启这个设置也会优化成一个。那么这个参数到底有什么用?multi group by又如何使用呢?