Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hive数据倾斜的一般解决思路 #25

Open
Joldnine opened this issue Sep 13, 2018 · 0 comments
Open

Hive数据倾斜的一般解决思路 #25

Joldnine opened this issue Sep 13, 2018 · 0 comments
Labels

Comments

@Joldnine
Copy link
Owner

Joldnine commented Sep 13, 2018

用Hive做ETL的时候,经常会遇到数据倾斜(Data Stew)的问题,记录总结一下。

分类

平时大概率遇到的可能有以下几类:

  1. join
  2. group by
  3. count distinct

解决办法

join

join时的数据倾斜一般是因为某些key对应的数据量比较大。思路一般是:

1. 数据去重或者裁剪

2. 如果是大表join小表,使用mapjoin

3. 如果知道热点的key的具体值,可以用skewjoin。

4. 思考业务上这样join是不是必须的,这种大量数据的key进行笛卡尔积(Cartesian product)是否合理,有没有变通方法

5. 在特定情况下,以上四种方法都没办法解决,需要具体情况具体分析。这里,我们可以挑一个大商家的经典例子分析一下。

我们有2个表,一个pv表,一个seller表。
dwd_pv 流量表字段:
visit_time, product_id, seller_id
假设有10亿行
dim_seller 卖家表字段:
seller_id, seller_name
假设有一千万行

Query:

SELECT visit_time, product_id, pv.seller_id, seller_name
FROM dwd_pv AS pv
LEFT OUTER JOIN dim_seller AS slr
ON pv.seller_id = slr.seller_id;

这就是一个普通的补字段SQL,但是在某些个seller流量特别大的情况下会发生数据倾斜。
为了解决这个问题,我们先了解一下HIVE里的join(Shuffle Join)发生了什么:

  1. map:
  2. shuffle:
  3. reduce:
    吃饭去了,待续

group by

group by 造成的数据倾斜和join类似,group by里的某个字段数据量太大。思路一般是:

  1. 数据去重或者裁剪。
  2. MRR做法,group by两次:第一次先在小一点的粒度上group进行初步汇总,目的是把大量数据的字段打散防止热点,然后在目标粒度上对汇总过的数据再group。

count distinct

思路:
key splitting。

@Joldnine Joldnine added the Hide label Sep 13, 2018
@Joldnine Joldnine changed the title 数据倾斜的一般解决思路 大数据ETL数据倾斜的一般解决思路 Sep 17, 2018
@Joldnine Joldnine added ETL and removed Hide labels Sep 26, 2018
@Joldnine Joldnine changed the title 大数据ETL数据倾斜的一般解决思路 数据倾斜的一般解决思路 Dec 7, 2018
@Joldnine Joldnine changed the title 数据倾斜的一般解决思路 Hive数据倾斜的一般解决思路 Dec 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant