hive学习之四:hive文件格式以及压缩编码

1。文件格式及压缩编码
   当前hive版本支持的编码类型:
   set io.compression.codecs;
   org.apache.hadoop.io.compress.GzipCodec,--压缩后不可分割
   org.apache.hadoop.io.compress.DefaultCodec,--默认
   org.apache.hadoop.io.compress.SnappyCodec,--压缩后不可分割
   据说bzip2和lzo压缩支持分割,我的hive版本里没有(0.14)
   默认的文件格式是文本文件(textfile,sequencefile,rcfile):
   set hive.default.fileformat;
   TextFile--默认
   sequencefile--二进制,可分割,有NONE,RECORD,BLOCK三种方式,一般BLOCK
   rcfile--行列结合存储方式,高效。建议使用。
  
   看表存储的文件格式,看建表语句:
   hive>show create table sas_atpt;
   STORED AS INPUTFORMAT
  'org.apache.hadoop.mapred.SequenceFileInputFormat'
   OUTPUTFORMAT
  'org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat'
   在输出信息的最后面可看出是SequenceFile
   看其压缩编码格式:
   hadoop fs -text /spdbccc/data/dest/SAS/SAS_ATPT/dt=20160506/000000_0|head -n 1;
   16/05/18 10:01:34 INFO compress.CodecPool: Got brand-new decompressor [.snappy]
   16/05/18 10:01:34 INFO compress.CodecPool: Got brand-new decompressor [.snappy]
   16/05/18 10:01:34 INFO compress.CodecPool: Got brand-new decompressor [.snappy]
   16/05/18 10:01:34 INFO compress.CodecPool: Got brand-new decompressor [.snappy]
            16883528|C|6048|20160506|22531555|2167521675225315556048835429|156.0|4047398908347862|20160505|18.0|终止退费―分期折(分期宝)| ||0000|000|0.0
  可看出是snappy压缩编码格式。如果没有压缩直接显示内容。
  看文件记录数:
  hadoop fs -text /spdbccc/data/dest/SAS/SAS_ATPT/dt=20160506/000000_0|wc -l
  --------------设置中间结果压缩(map输出压缩)--------------
  set hive.exec.compress.intermediate=true;
  set mapred.map.output.compression.codec=org.apache.hadoop.io.compress.SnappyCodec
  --------------最终输出结果压缩---------------------------
  set hive.exec.compress.output=true;
  set mapred.output.compression.type=BLOCK;---指定sequencefile压缩方式
  set mapred.output.compression.codec=org.apache.hadoop.io.compress.SnappyCodec;
3。相同压缩编码不同文件格式测试
  表名:sas_amed_req
  snappy压缩编码,sequencefile
  数据量:22003205
  大小:2.1 G
  create table sas_amed_rc like sas_amed;
  set hive.exec.compress.output=true;
  set mapred.output.compression.codec=org.apache.hadoop.io.compress.SnappyCodec;
  alter table sas_amed_rc set fileformat rcfile;
  insert overwrite table sas_amed_rc partition(dt) select * from  sas_amed where dt='20160407';
  数据量不变,大小变为1.7G。
  查询性能测试:测试sql:
  select ED_CUST_NBR,
         ED_ACCT_NBR,   
         ED_CARD_NBR,   
         ED_APPLICATION_ID,
         ED_LOGO,      
         ED_DATE_FIRST_CARD_VERIFY,
         ED_CDFRM
       --row_number() over (distribute by ED_APPLICATION_ID sort by ED_CARD_SEQ desc) rank ------1
   from sas_amed_rc
   where dt='20160407' and ED_PRIMARY_CARD_IND='1' limit 100;
   Time taken: 43.229 seconds, Fetched: 100 row(s)
   更换上述sql的表名为sas_amed_rc,结果为:
   Time taken: 43.465 seconds, Fetched: 100 row(s)
   预测是rcfile查询更快,但是没什么差别。将1处注释掉查询,rcfile比sequencefile快了4秒左右。再测试join速度
   select a.* from
   (select ED_CUST_NBR,
          ED_ACCT_NBR,   
          ED_CARD_NBR,   
          ED_APPLICATION_ID,
          ED_LOGO,      
          ED_DATE_FIRST_CARD_VERIFY,
          ED_CDFRM
    from sas_amed
    where dt='20160407' and ED_PRIMARY_CARD_IND='1') a inner join (select * from sas_nasrdwn where dt='20160407') b 
    on a.ED_APPLICATION_ID=b.NASRDW_APPL_ID;
    rcfile+snappycodec:Time taken: 32.476 seconds, Fetched: 42011 row(s)
    seqfile+snappycodec:Time taken: 35.36 seconds, Fetched: 42011 row(s)
    确实快了不少。从这点上来看,rcfile在查询时候的优势还是比sequencefile高的。
3。不同压缩编码相同文件格式测试
   文件格式:rcfile 测试这2个不同的编码:default,snappy,default压缩后1.2个G,压缩率高于snappy,gzip压缩后930.7M,压缩比最高。
   Caused by: org.apache.hadoop.hive.ql.metadata.HiveException:
   java.lang.IllegalArgumentException: Compression codec org.apache.hadoop.io.compress.org.apache.hadoop.io.compress.GzipCodec was not found.
   select a.* from
   (select ED_CUST_NBR,
          ED_ACCT_NBR,   
          ED_CARD_NBR,   
          ED_APPLICATION_ID,
          ED_LOGO,      
          ED_DATE_FIRST_CARD_VERIFY,
          ED_CDFRM
    from sas_amed_rc_gzip
    where dt='20160407' and ED_PRIMARY_CARD_IND='1') a inner join (select * from sas_nasrdwn where dt='20160407') b 
    on a.ED_APPLICATION_ID=b.NASRDW_APPL_ID;
    rcfile+defaultcodec:Time taken: 91.915 seconds, Fetched: 42011 row(s)
    rcfile+snappycodec:Time taken: 38.182 seconds, Fetched: 42011 row(s)
    rcfile+gzipcodec:Time taken: 39.558 seconds, Fetched: 42011 row(s)
    综上所述选择rcfile+snappycodec文件格式和压缩编码优于其他。建议采用这种组合方式。

4。判断是否数据倾斜
   1.1.如果任务卡在reduce阶段不动或者执行非常缓慢,在排除其他情况下大致可认为出现了数据倾斜(hive sql中出现的join,group by,distinct等情况都有可能)。
   1.2.任务执行完成,但是耗费的时间过长,从YARN或者MR的监控页面上看job执行的各个reduce数的耗时情况。例如某个job10个map,20个reduce。map大约20秒左右完成,reduce基本在10秒
       左右完成,但某一个需要3分钟完成,可基本判断出现了数据倾斜。

其本质原因:是某个key过于集中(包括空值过多),分布不均匀造成的,解决方法在优化篇中有。

5。设置hive作业执行的队列;
   set mapreduce.job.queuename=hive(队列名称)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值