内容简介:如何用Apache Pig输出压缩格式的SequenceFile
如果你要用Apache Pig读取这种类型的数据,可以用 PiggyBank 中的SequenceFileLoader——我没有用过,但肯定是没问题的。
但是,如果你保存在SequenceFile中的key或value是 ThriftWritable 类型的数据,那么,要用Pig来 load & store 这种数据,就不那么容易了。
幸好我们有Twitter,它已经帮我们做好了这个工作。利用其开源的 Elephant Bird ,我们可以轻松做到这一点。
Elephant Bird 中的 SequenceFileLoader 以及 SequenceFileStorage 就是用来干这个的。
例如,load数据的做法是:
A = LOAD 'xxx' USING com.twitter.elephantbird.pig.load.SequenceFileLoader( '-c com.mediav.elephantbird.pig.util.BooleanWritableConverter', '-c com.twitter.elephantbird.pig.util.ThriftWritableConverter com.codelast.MyThriftClass');
其中,这份SequenceFile的key是BooleanWritable类型,value是ThriftWritable类型,它对应的Thrift类是MyThriftClass,这是一个自定义的Thrift class。
文章来源: http://www.codelast.com/
store 数据的做法是:
STORE B INTO 'xxx' USING com.twitter.elephantbird.pig.store.SequenceFileStorage( '-c com.mediav.elephantbird.pig.util.BooleanWritableConverter', '-c com.twitter.elephantbird.pig.util.ThriftWritableConverter com.codelast.MyThriftClass');
其中,对key和value的说明和上面一样。
这样,就可以实现加载以及存储SequenceFile了。
文章来源: http://www.codelast.com/
但是你会发现,这样输出的SequenceFile是未压缩的,所以文件体积比较大。如果要压缩,该怎么做呢?
答案就是在Pig脚本中添加以下几句话就OK了:
SET output.compression.enabled 'true'; SET mapreduce.output.fileoutputformat.compress.type 'BLOCK'; SET output.compression.codec 'org.apache.hadoop.io.compress.DefaultCodec';
这会使得输出的SequenceFile是BLOCK压缩类型,默认压缩编码的文件。
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 如何用Apache Pig输出压缩格式的SequenceFile
- 如何用Apache Pig输出压缩格式的SequenceFile
- Yii2压缩PHP中模板代码的输出
- 2. Python中的基本输入、输出、格式化输出
- golang压缩和解压缩zip文件
- bitcoin:压缩公钥与未压缩公钥
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Bulletproof Web Design
Dan Cederholm / New Riders Press / 28 July, 2005 / $39.99
No matter how visually appealing or packed with content a Web site is, it isn't succeeding if it's not reaching the widest possible audience. Designers who get this guide can be assured their Web site......一起来看看 《Bulletproof Web Design》 这本书的介绍吧!
RGB CMYK 转换工具
RGB CMYK 互转工具
HEX CMYK 转换工具
HEX CMYK 互转工具