Hive map阶段缓慢

不同数据类型关联产生数据倾斜

场景:用户表中user_id字段为int,log表中user_id字段既有string类型也有int类型。当按照user_id进行两个表的Join操作时,默认的Hash操作会按int型的id来进行分配,这样会导致所有string类型id的记录都分配到一个Reducer中。

解决方法:把数字类型转换成字符串类型

select * from users a

  left outer join logs b

  on a.usr_id = cast(b.user_id as string)

 

现实描述:(默认是mapjoin)

fin_ihotel_ceq_external_ctrip表(大表)的countryid和cityid 为int类型 ,

而dim_ihotel_country_ctrip(小表)的country_id,dim_ihotel_city_ctrip(小表)的city_id都为string类型

from fin_ihotel_ceq_external_ctrip t1 
left join dim_ihotel_country_ctrip t2 
on t1.countryid=t2.country_id
left join dim_ihotel_city_ctrip t3 
on t1.cityid=t3.city_id and t1.countryid=t2.country_id 

改成

from fin_ihotel_ceq_external_ctrip t1

left join dim_ihotel_country_ctrip t2

on cast(t1.countryid as string)=t2.country_id

left join dim_ihotel_city_ctrip t3

on cast(t1.cityid as string)=t3.city_id and cast(t1.countryid as string)=t2.country_id

速度提升1个半小时到3分钟

以后需要关联的字段最好都 用string类型定义

附其他参考:

Hive map阶段缓慢,优化过程详细分析

http://bigdata.51cto.com/art/201703/535606.htm

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值