温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

hive sql 优化 数据倾斜

发布时间:2020-06-27 15:56:36 来源:网络 阅读:1223 作者:r7raul 栏目:大数据


 

此脚本运行速度慢,主要是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 ;

        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 这句SQLBI加上如下配置,

 

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可以在可控时间内完成。


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI