数据湖探索 DLI-执行SQL作业时产生数据倾斜怎么办?:Group By数据倾斜解决方案

时间:2024-11-06 21:53:30

Group By数据倾斜解决方案

取部分数据执行select count(*) as sum,Key from tbl group by Key order by sum desc查询具体是哪些key引起的数据倾斜。

然后对于倾斜Key单独做处理,加盐让其先将他分为多个task分别统计,最后再对分开统计结果进行结合统计。

例如:如下SQL示例,假设已知倾斜key为'Key01',导致单个task处理大量数据,做如下处理:

SELECT
  a.Key,
  SUM(a.sum) AS Cnt
FROM
  (
    SELECT
      Key,
      count(*) AS sum
    FROM
      tbl
    GROUP BY
      Key,
      CASE
        WHEN KEY = 'Key01' THEN floor(random () * 200)
        ELSE 0
      END
  ) a
GROUP BY
  a.Key;
support.huaweicloud.com/dli_faq/dli_03_0093.html