hive数据压缩技术001

来源:互联网 发布:安慕希网络促销方案 编辑:程序博客网 时间:2024/06/03 07:44

一、 压缩方案比较


关于Hadoop HDFS文件的压缩格式选择, 我们通过多个真实的Track数据做测试,得出结论如下:
1. 系统的默认压缩编码方式 DefaultCodec 无论在压缩性能上还是压缩比上,都优于GZIP 压缩编码。这一点与网上的一些观点不大一致,网上不少人认为GZIP的压缩比要高一些,估计和Cloudera的封装及我们Track的数据类型有关。
2. Hive文件的RCFile 的在压缩比, 压缩效率,及查询效率上都优于SEQENCE FILE (包括RECORD, BLOCK 级别) 。
3. 所有压缩文件均可以正常解压为TEXT 文件,但比原始文件略大,可能是行列重组造成的。
关于压缩文件对于其他组件是适用性如下:
1.  Pig 不支持任何形式的压缩文件。
2.  Impala 目前支持SequenceFile的压缩格式,但还不支持RCFile的压缩格式。

综上所述: 
从压缩及查询的空间和时间性能上来说,DefaultCodeC + RCFile的压缩方式均为最优, 但使用该方式,会使得Pig 和Impala 无法使用(Impala的不兼容不确定是否是暂时的)。
而DefaultCodeC + SequenceFile 在压缩比,查询性能上略差于RCFile (压缩比约 6:5), 但可以支持 Impala实时查询。

推荐方案:

 采用RCFile 方式压缩历史数据。FackBook全部hive表都用RCFile存数据。


二、 局部压缩方法
只需要两步:
1. 创建表时指定压缩方式,默认不压缩,以下为示例:
create external table track_hist(
id bigint, url string, referer string, keyword string, type int, gu_id string,
…/*此处省略中间部分字段*/ …, string,ext_field10 string)
partitioned by (ds string) stored as RCFile location '/data/share/track_histk' ;


2. 插入数据是设定立即压缩
SET hive.exec.compress.output=true;
insert overwrite table track_hist partition(ds='2013-01-01')
select id,url, …/*此处省略中间部分字段*/ …, ext_field10 from trackinfo 
where ds='2013-01-01';

三、全局方式,修改属性文件


在hive-site.xml中设置:
<property>
  <name>hive.default.fileformat</name>
  <value>RCFile</value>
  <description>Default file format for CREATE TABLE statement. Options are TextFile and SequenceFile. Users can explicitly say CREAT
E TABLE ... STORED AS &lt;TEXTFILE|SEQUENCEFILE&gt; to override</description>
</property>
<property>
  <name>hive.exec.compress.output</name>
  <value>true</value>
  <description> This controls whether the final outputs of a query (to a local/hdfs file or a hive table) is compressed. The compres
sion codec and other options are determined from hadoop config variables mapred.output.compress* </description>
</property>


四、注意事项
1、Map阶段输出不进行压缩
2、对输出文本进行处理时不压缩
原创粉丝点击