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