Sequence Files等,本身就支援split,經過壓縮之後一樣是支援split的。
綜上,我們hadoop2.4叢集要求RCFile+gzip是有一定道理的,首先RCFile格式的檔案支援按列儲存。同一時候支援split,而gzip的壓縮率比較高,並且壓縮/解壓速度也比較快,所以RCFile格式的檔案經過gzip壓縮後既能保證檔案能split,還能保證非常高壓縮/解壓速度和壓縮比。
以上說了半天題外話,下面來進入主題來說一下如何在不替換叢集本地庫檔案,不重新啟動hadoop進程,也即在hadoop的client就能解決支援snappy壓縮的問題的方法:
1、編譯snappy本地庫,編譯之後snappy本地庫檔案地址:/data0/liangjun/snappy/
參考地址:http://www.tuicool.com/articles/yiiiY3R
2、又一次編譯libhadoop.so檔案,編譯時間通過-Dsnappy.prefix指定snappy本地庫檔案地址編譯:
mvn clean package -Pdist -Dtar -Pnative -Dsnappy.prefix=/data0/liangjun/snappy/ -DskipTests
註:我測試了一下,通過-Drequire.snappy編譯的libhadoop.so也是可行的:
mvn clean package -Pdist,native -DskipTests -Drequire.snappy
3、運行完上面兩步之後,終於僅僅須要拿到libhadoop.so和libsnappy.so.1兩個檔案(僅僅須要這兩個檔案。其它得經過我測試都過濾掉了)。下面是MapReduce和hive的使用snappy壓縮的範例:
(1)、MapReduce。將編譯好的本地庫加到DistributedCache中就能夠:
在測試環境的clientmapred-site.xml檔案加入下面兩個配置項以支援map端資料的時候按snappy壓縮:
<property> <name>mapreduce.map.output.compress</name> <value>true</value> <final>true</final> </property> <property> <name>mapreduce.map.output.compress.codec</name> <value>org.apache.hadoop.io.compress.SnappyCodec</value> <final>true</final> </property>
上傳libhadoop.so和libhadoop.so到指定hdfs檔案夾/test/snappy/下。通過-files指定檔案:
hadoop jar hadoop-mapreduce-examples-2.4.0.jar wordcount -files hdfs://ns1/test/snappy/libhadoop.so,hdfs://ns1/test/snappy/libsnappy.so.1 /test/missdisk/ /test/wordcount
(2)、hive,通過add file指定檔案:
hive >add file libhadoop.so;hive >add file libsnappy.so.1;hive >select count(*) from ct_tmp_objrec;
表ct_tmp_objrec的資料是文字檔經過snappy壓縮的資料。ct_tmp_objrec儲存格式是普通的文字格式設定。
執行hql之後。發現snappy格式的資料可以正常處理計算了,可是200+M的檔案僅僅能由一個map任務處理,既不支援split。
==========================================================
下面部分是就RCFile+snappy的資料是否支援split的測試:
1、建立測試表snappy_test,該表和前面的ct_tmp_objrec列全然同樣,僅僅是hive表格儲存體格式換成了RCFile:
CREATE EXTERNAL TABLE `snappy_test`( `from_id` string, `to_id` string, `mention_type` bigint, `repost_flag` bigint, `weight` double, `confidence` double, `from_uid` string, `to_object_label` string, `count` bigint, `last_modified` string, `time` string, `mblog_spam` bigint, `mblog_simhash` string, `mblog_dupnum` bigint, `mblog_attribute` bigint, `user_quality` bigint, `user_type` bigint, `old_weight` double, `obj_pos` bigint, `quality` bigint)ROW FORMAT SERDE ‘org.apache.hadoop.hive.serde2.columnar.LazyBinaryColumnarSerDe‘STORED AS INPUTFORMAT ‘org.apache.hadoop.hive.ql.io.RCFileInputFormat‘OUTPUTFORMAT ‘org.apache.hadoop.hive.ql.io.RCFileOutputFormat‘LOCATION ‘hdfs://ns1/user/liangjun/warehouse/tables/snappy_test‘
2、將ct_tmp_objrec中plain text+snappy壓縮的資料轉成snappy_test中RCFile+gzip壓縮的資料:
hive >add file libhadoop.so;hive >add file libsnappy.so.1;hive >set hive.exec.compress.output=true;hive >set mapred.output.compression.codec=org.apache.hadoop.io.compress.SnappyCodec;hive >INSERT OVERWRITE table snappy_test select from_id,to_id,mention_type,repost_flag,weight,confidence,from_uid,to_object_label,count,last_modified,time,mblog_spam,mblog_simhash,mblog_dupnum,mblog_attribute,user_quality,user_type,old_weight,obj_pos,quality from ct_tmp_objrec;
3、查詢snappy_test中的RCFile+snappy資料看能否split
hive >add file libhadoop.so;hive >add file libsnappy.so.1;hive >select count(*) from snappy_test;
執行hql之後,發現RCFile+snappy的資料可以正常處理計算,同一時候200+M的檔案split成兩個map任務處理。測試完畢。
參考地址:
http://blog.cloudera.com/blog/2011/09/snappy-and-hadoop/
http://blog.csdn.net/czw698/article/details/38387657
http://www.linuxidc.com/Linux/2014-05/101230.htm
http://book.2cto.com/201305/21922.html
http://blog.csdn.net/czw698/article/details/38387657
http://blog.csdn.net/czw698/article/details/38398399
http://www.tuicool.com/articles/yiiiY3R