您的位置:首页 > 数据库

hive sql 优化 数据倾斜

2015-05-13 12:48 239 查看
此脚本运行速度慢,主要是reduce端数据倾斜导致的,了解到dw.fct_traffic_navpage_path_detl表是用来收集用户点击数据的,那么最终
购物车和下单的点击肯定极少,所以此表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 ; 151722135select 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会生成BROADCASTsethive.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可以在可控时间内完成。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: