hive中的資料傾斜優化
阿新 • • 發佈:2021-10-15
# 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