有时虽然某个 key 为空对应的数据很多,但是相应的数据不是异常数据,必须要包含在
join 的结果中,此时我们可以表 a 中 key 为空的字段赋一个随机的值,使得数据随机均匀地
分不到不同的 reducer 上。
实例:
不随机分布空 null 值:
(1)设置 5 个 reduce 个数
set mapreduce.job.reduces = 5;
(2) JOIN 两张表
insert overwrite table jointable
select n.* from nullidtable n left join ori b on n.id = b.id;
结果: 出现了数据倾斜, 某些 reducer 的资源消耗远大于其他 reducer。
随机分布空 null 值
(1)设置 5 个 reduce 个数
set mapreduce.job.reduces = 5;
(2) JOIN 两张表
insert overwrite table jointable
select n.* from nullidtable n full join ori o on
case when n.id is null then concat('hive', rand()) else n.id end
= o.id;
结果:消除了数据倾斜,负载均衡 reducer 的资源消耗