hive的数据倾斜
主要是reduce端产生的
reducetask–0.95*datanode个数
group 如果和聚合函数一起使用,默认在map端开始combiner,不会产生数据倾斜
产生数据倾斜的根本原因就是key分配不均匀
常见场景:
一.null值过多
解决:1.null值不参与连接
select a.,b. from log a join user b on a.userid=b.userid and a.userid is not null;
2.连接的时候不加null,之后另外拼接
select a.,b. from log a join user b on a.userid=b.userid and a.userid is not null
union all
select * from log where userid is null;
union all 和union的区别
union 会去重
3.给null值加随机数,或者将null转化为随机数,相当于把null值打散了
nvl(userid,rand()) 可以给这个随机数一个范围,一个不在正常useid的范围,方便以后查询
二.参与连接的数据类型不统一
select a.,b. from log a join user b on a.userid=b.userid
log里的string类型,user里是int类型, 345+空格 转化为int就会变成null
关联的时候会将string类型转化为int类型
select a.,b. from log a join user b on cast(trim(a.userid) as int)=b