内容简介:如果你要用Apache Pig读取这种类型的数据,可以用 PiggyBank 中的SequenceFileLoader——我没有用过,但肯定是没问题的。但是,如果你保存在SequenceFile中的key或value是幸好我们有Twitter,它已经帮我们做好了这个工作。利用其开源的
如果你要用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
- 如何用Apache Pig输出压缩格式的SequenceFile
- Yii2压缩PHP中模板代码的输出
- 2. Python中的基本输入、输出、格式化输出
- golang压缩和解压缩zip文件
- bitcoin:压缩公钥与未压缩公钥
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Coming of Age in Second Life
Tom Boellstorff / Princeton University Press / 2008-04-21 / USD 29.95
The gap between the virtual and the physical, and its effect on the ideas of personhood and relationships, is the most interesting aspect of Boellstorff's analysis... Boellstorff's portrayal of a virt......一起来看看 《Coming of Age in Second Life》 这本书的介绍吧!