分享

【求助】关于HIVE数据倾斜的问题

大家好:

首先这是我的HQL语句:
  1. insert into table YHX_Report_SourceSplit select /*+mapjoin(sensor_shopinfo_localId) */ sensor_shopinfo_localId.localId,localId,'','','',from_unixtime(rawdata_sensor_a.rd_sen_ts,'yyyy-MM-dd HH:00:00'),from_unixtime(rawdata_sensor_a.rd_sen_ts,'yyyy-MM-dd'),from_unixtime(rawdata_sensor_a.rd_sen_ts),rawdata_sensor_a.rd_sen_ts,if(rawdata_sensor_a.rd_sen_rssi>=sensor_shopinfo_localId.maxRssi,'1','2'),'1',rawdata_sensor_a.rd_sen_devmac,rawdata_sensor_a.rd_sen_smac,rawdata_sensor_a.rd_sen_apmac,rawdata_sensor_a.rd_sen_rssi,'','','','', '' from sensor_shopinfo_localId left outer join rawdata_sensor_a on datediff(from_unixtime(rd_sen_ts),'2014-11-29')=0 and sensor_shopinfo_localId.sensorMac = rawdata_sensor_a.rd_sen_smac;
复制代码

我并没有做groupby和distinct,只是对于A表的数据做了拆分存储至B表中。

最终数据结果如下:
大数据入库test1.png


可以看出来,一共产生了13个REDUCE,但大家细看一下,大多的REDUCE都是没有什么数据的,这代表了出现了严重的数据倾斜……
我试着调整了set hive.groupby.skewindata=true ;   这个参数,但是这个参数貌似只是针对groupby的,所以失败了。

所以我想求助一下,我应该如何解决我这样的数据倾斜问题?  

谢谢
hark

我的博客 http://www.cnblogs.com/hark0623

已有(9)人评论

跳转到指定楼层
lixiaoliang7 发表于 2014-12-25 11:14:41
好象有点思路了,我使用explain看了HIVE的执行计划
看到了
  1. Reduce Output Operator
  2.                 key expressions: rd_sen_smac (type: string)
  3.                 sort order: +
  4.                 Map-reduce partition columns: rd_sen_smac (type: string)
  5.                 Statistics: Num rows: 1 Data size: 503 Basic stats: COMPLETE Column stats: NONE
  6.                 value expressions: rd_sen_smac (type: string), rd_sen_devmac (type: string), rd_sen_rssi (type: string), rd_sen_ts (type: int), rd_sen_apmac (type: string)
复制代码

貌似Reduce的key是使用两个表关联的字段 rd_sen_smac

然后我对于数据按又进行了rd_sen_smac又做了groupby,求每个key的数量,发现数量如下:
  1. rd_sen_smac     _c1
  2. 0023cd02041d    38045088
  3. 0023cd020457    83382687
  4. 0023cd020540    65777040
  5. 0023cd02086d    449712
复制代码

我擦,那这个怎么搞啊…    只有四个KEY,但是又有13个reduce。。。

回复

使用道具 举报

lixiaoliang7 发表于 2014-12-25 11:24:52
这是整个执行计划,大家帮忙看一下哇:
  1. Explain
  2. STAGE DEPENDENCIES:
  3.   Stage-5 is a root stage , consists of Stage-1
  4.   Stage-1
  5.   Stage-0 depends on stages: Stage-1
  6.   Stage-2 depends on stages: Stage-0
  7. STAGE PLANS:
  8.   Stage: Stage-5
  9.     Conditional Operator
  10.   Stage: Stage-1
  11.     Map Reduce
  12.       Map Operator Tree:
  13.           TableScan
  14.             alias: rawdata_sensor_a
  15.             Statistics: Num rows: 3 Data size: 1510 Basic stats: COMPLETE Column stats: NONE
  16.             Filter Operator
  17.               predicate: (datediff(from_unixtime(rd_sen_ts), '2014-11-29') = 0) (type: boolean)
  18.               Statistics: Num rows: 1 Data size: 503 Basic stats: COMPLETE Column stats: NONE
  19.               Reduce Output Operator
  20.                 key expressions: rd_sen_smac (type: string)
  21.                 sort order: +
  22.                 Map-reduce partition columns: rd_sen_smac (type: string)
  23.                 Statistics: Num rows: 1 Data size: 503 Basic stats: COMPLETE Column stats: NONE
  24.                 value expressions: rd_sen_smac (type: string), rd_sen_devmac (type: string), rd_sen_rssi (type: string), rd_sen_ts (type: int), rd_sen_apmac (type: string)
  25.           TableScan
  26.             alias: sensor_shopinfo_localid
  27.             Statistics: Num rows: 8 Data size: 280 Basic stats: COMPLETE Column stats: NONE
  28.             Reduce Output Operator
  29.               key expressions: sensormac (type: string)
  30.               sort order: +
  31.               Map-reduce partition columns: sensormac (type: string)
  32.               Statistics: Num rows: 8 Data size: 280 Basic stats: COMPLETE Column stats: NONE
  33.               value expressions: localid (type: string), maxrssi (type: int)
  34.       Reduce Operator Tree:
  35.         Join Operator
  36.           condition map:
  37.                Left Outer Join0 to 1
  38.           condition expressions:
  39.             0 {VALUE._col2} {VALUE._col3}
  40.             1 {VALUE._col0} {VALUE._col2} {VALUE._col3} {VALUE._col4} {VALUE._col5}
  41.           outputColumnNames: _col2, _col3, _col6, _col8, _col9, _col10, _col11
  42.           Statistics: Num rows: 8 Data size: 308 Basic stats: COMPLETE Column stats: NONE
  43.           Select Operator
  44.             expressions: _col2 (type: string), _col2 (type: string), '' (type: string), '' (type: string), '' (type: string), CAST( from_unixtime(_col10, 'yyyy-MM-dd HH:00:00') AS TIMESTAMP) (type: timestamp), CAST( from_unixtime(_col10, 'yyyy-MM-dd') AS DATE) (type: date), CAST( from_unixtime(_col10) AS TIMESTAMP) (type: timestamp), _col10 (type: int), UDFToByte(if((_col9 >= _col3), '1', '2')) (type: tinyint), UDFToByte('1') (type: tinyint), _col8 (type: string), _col6 (type: string), _col11 (type: string), UDFToFloat(_col9) (type: float), UDFToFloat('') (type: float), UDFToFloat('') (type: float), UDFToInteger('') (type: int), UDFToDouble('') (type: double), UDFToDouble('') (type: double)
  45.             outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col9, _col10, _col11, _col12, _col13, _col14, _col15, _col16, _col17, _col18, _col19
  46.             Statistics: Num rows: 8 Data size: 308 Basic stats: COMPLETE Column stats: NONE
  47.             File Output Operator
  48.               compressed: false
  49.               Statistics: Num rows: 8 Data size: 308 Basic stats: COMPLETE Column stats: NONE
  50.               table:
  51.                   input format: org.apache.hadoop.mapred.TextInputFormat
  52.                   output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
  53.                   serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
  54.                   name: yhx_report_test.yhx_report_sourcesplit
  55.   Stage: Stage-0
  56.     Move Operator
  57.       tables:
  58.           replace: false
  59.           table:
  60.               input format: org.apache.hadoop.mapred.TextInputFormat
  61.               output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
  62.               serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
  63.               name: yhx_report_test.yhx_report_sourcesplit
  64.   Stage: Stage-2
  65.     Stats-Aggr Operator
  66. Time taken: 0.266 seconds, Fetched: 69 row(s)
复制代码



回复

使用道具 举报

lixiaoliang7 发表于 2014-12-25 11:26:51
然后左表的数据量只有几条,很小的。 右表大概10个G左右数据
回复

使用道具 举报

desehawk 发表于 2014-12-25 12:46:22
楼主已经做了优化,并且从执行计划,只有一个job。

看到楼主的sql中有空值,可以做如下优化


select *  from log a  left outer join users b  on case when a.user_id is null then concat(‘hive’,rand() ) else a.user_id end = b.user_id;

上面只是例子,楼主可以尝试,把空值替换为某个特定的值
回复

使用道具 举报

lixiaoliang7 发表于 2014-12-25 14:25:00
本帖最后由 lixiaoliang7 于 2014-12-25 10:28 编辑
desehawk 发表于 2014-12-25 08:46
楼主已经做了优化,并且从执行计划,只有一个job。

看到楼主的sql中有空值,可以做如下优化

其实关键在于,有的reduce负担太大,有的reduce负担太小。 这个问题不知道如何解决
回复

使用道具 举报

rsgg03 发表于 2014-12-25 17:32:56
可能并非楼主所想,数据倾斜是最后map或则reduce会执行很慢。
如果有的输出文件为空,楼主,可以设置下reduce的个数。
或则最后合并下,在输出。
回复

使用道具 举报

lixiaoliang7 发表于 2014-12-25 18:07:32
rsgg03 发表于 2014-12-25 13:32
可能并非楼主所想,数据倾斜是最后map或则reduce会执行很慢。
如果有的输出文件为空,楼主,可以设置下red ...

谢谢了。 我现在先去处理别的问题。
完事后再来试一下这个事情。如有解决,我还会在该贴子中留言的。
多谢版主大人的热心回复
回复

使用道具 举报

zzuyao 发表于 2015-3-13 17:02:17
楼主,问题怎么样了
回复

使用道具 举报

ainubis 发表于 2015-3-28 15:56:26
飘过,学习学习!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条