其他分享
首页 > 其他分享> > hive中的数据倾斜优化

hive中的数据倾斜优化

作者:互联网

# hive的倾斜种类比较多,下面主要分析join 时,key倾斜的情况,其他案例后续再补充

1. 大表mapjoin 小表时key值中出现null,空字符特别多,其他普通key特别少时,就会出现单个reduce的运行缓慢,远远超出其他reduce 的运行时间,例如

select a.id,b.id,a.xxxx
from a
left join b
on a.id=b=id

2. 某个长时间运行reduce 日志如下, join 的过程超出了两个小时

 

 3. 通过分析a 表的id 特征值后发现, null 值特别多

select a.id,count(1) cn from a group by id order by cn desc limit 100

+---------------+------------+
| id | cn |
+---------------+------------+
| NULL | 210192843 |
| xxxxxxxxx1 | 5531250 |
| xxxxxxxxx2 | 3547506 |
| xxxxxxxxx3 | 3125790 |
| xxxxxxxxx4 | 2493601 |
| xxxxxxxxx5 | 2478931 |
| xxxxxxxxx6 | 2290155 |
| xxxxxxxxx7 | 2248076 |

4. 通过调整sql 语句如下,重新运行后,时间大幅缩小

set hive.optimize.skewjoin = true;
set hive.skewjoin.key = 100000;
set hive.auto.convert.join=true;
set hive.mapjoin.smalltable.filesize = 100000000;
select a.id,b.id,a.xxxx
from a
left join b
on a.id=b=id
union all
where a.id is null
select a.id,b.id,a.xxxx
from a
left join b
on a.id=b=id
where a.id is not null

  

 

标签:set,join,hive,key,倾斜,优化,id,select
来源: https://www.cnblogs.com/tommyjiang/p/15410122.html