Hive数据压缩笔记

               

Hive数据压缩

本文介绍Hadoop系统中Hive数据压缩方案的比较结果及具体压缩方法。

一、压缩方案比较

关于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_idstring,

…/*此处省略中间部分字段*/ …, 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_histpartition(ds='2013-01-01')

select id,url, …/*此处省略中间部分字段*/ …, ext_field10 fromtrackinfo

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<TEXTFILE|SEQUENCEFILE> 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 determinedfrom hadoop config variables mapred.output.compress* </description>

</property>

四、注意事项

1、Map阶段输出不进行压缩

2、对输出文本进行处理时不压缩

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自blog.csdn.net/qq_43668007/article/details/87612793