hivesql优化数据倾斜

此脚本运行速度慢,主要是reduce端数据倾斜导致的,了解到dw.fct_traffic_navpage_path_detl表是用来收集用户点击数据的,那么最终

创新互联一直在为企业提供服务,多年的磨炼,使我们在创意设计,营销型网站到技术研发拥有了开发经验。我们擅长倾听企业需求,挖掘用户对产品需求服务价值,为企业制作有用的创意设计体验。核心团队拥有超过10余年以上行业经验,涵盖创意,策化,开发等专业领域,公司涉及领域有基础互联网服务绵阳机房托管App定制开发、手机移动建站、网页设计、网络整合营销。

购物车和下单的点击肯定极少,所以此表ordr_code字段为空和cart_prod_id字段为NULL的数据量极大,如下所示:

select ordr_code,count(*) as a from dw.fct_traffic_navpage_path_detl  where ds = '2015-05-10'  group by ordr_code having a>10000 ;

        151722135

select cart_prod_id,count(*) as a fromdw.fct_traffic_navpage_path_detl   where ds = '2015-05-10'  groupby cart_prod_id having a>10000 ;

NULL    127233335

 

对于create table tmp_lifan_trfc_tpa as这句SQL,BI加上如下配置,

 

set hive.mapjoin.smalltable.filesize = 120000000; //因为 dw.univ_parnt_tranx_comb_detl表最大不超过120MB,如果是hive on tez要用hive.auto.convert.join.noconditionaltask.size ,这样tez会生成BROADCAST

sethive.auto.convert.join=true;

同时修改SQL如下语句:

from dw.fct_traffic_navpage_path_detl t

  left outer join dw.univ_parnt_tranx_comb_detl o //用mapjoin解决数据倾斜

    on t.ordr_code = o.parnt_ordr_code

   and t.cart_prod_id = o.comb_prod_id

   and o.ds = '2015-05-10'

  left outer join bic.cust_first_ordr_tranx f

   on case when o.end_user_id is null then cast(rand(9)*100as bigint)  else o.end_user_id end= f.end_user_id  //join后数倾斜用随机数避免倾斜 ,红色为修改部分

   and f.first_ordr_date_id = '2015-05-10'

where t.ds = '2015-05-10';

运行后SQL可以在可控时间内完成。


新闻名称:hivesql优化数据倾斜
URL网址:http://pwwzsj.com/article/jsspgs.html