此脚本运行速度慢,主要是reduce端数据倾斜致使的,了解到dw.fct_traffic_navpage_path_detl表是用来收集用户点击数据的,那么最终ide
购物车和下单的点击确定极少,因此此表ordr_code字段为空和cart_prod_id字段为NULL的数据量极大,以下所示:spa
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 ;code
151722135it
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 ;io
NULL 127233335table
对于create table tmp_lifan_trfc_tpa as 这句SQL,BI加上以下配置,ast
set hive.mapjoin.smalltable.filesize = 120000000; //由于 dw.univ_parnt_tranx_comb_detl表最大不超过120MB,若是是hive on tez要用hive.auto.convert.join.noconditionaltask.size ,这样tez会生成BROADCASTclass
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能够在可控时间内完成。