[Hadoop]
Apache Pig
バイナリファイルを読みたい
Load image to pig によると、SequenceFileLoaderを使えばファイルを再帰的に取得できるようだ。
Piggybank
- Javadoc
- BytesWriteable support in Piggybank SequenceFileLoader?
- Piggybankの BytesWritable クラスは使えないようだ・・・
elephant-bird
- Javadoc
-- -- Pig LoadFunc supporting conversion from key and value Writables stored within SequenceFiles to Pig tuples. Example usage: -- pairs = LOAD '$INPUT' USING com.twitter.elephantbird.pig.load.SequenceFileLoader ( '-c com.twitter.elephantbird.pig.util.IntWritableConverter', '-c com.twitter.elephantbird.pig.util.TextConverter' ) as ( key: int, value: chararray ); -- -- LzoPigStorage --
ZipLoaderを作る
Pig's loader function uses Hadoop's InputFormat. It takes each record from the RecordReader and converts it to a tuple (or whatever), so if you want to read zipped files you have to write your custom InputFormat/RecordReader anyhow.
PigのLoad関数はHadoopのInputFormatクラスを使用している。それはそれぞれのレコードに対してRecordReaderをとり、そしてTuple(かそれ以外の何か)に変換している。なので、zip圧縮されたファイルを読みたいのならば、どうしても自前のInputFormat/RecordReaderを書く必要がある。
そ~なのかー、ということで
作成した
使い方
%declare ZIP_LOADER 'com.cotdp.pigudf.ZipLoader'; REGISTER target/com-cotdp-hadoop-1.0-SNAPSHOT.jar A = LOAD 'src/test/resources/zip-01.zip' USING $ZIP_LOADER(); DUMP A;
ZipLoaderの課題
- ZIPファイル内の改行コードがとれない?(splittableにできない?)
- is gzip file in s3 as input splittable?
→ UDF Loader - one line in input result in multiple tuples のコメントを参考に改行コードをPigでとるようにした
ia-hadoop-tools
- 上記の課題を解決するソースを探しているとやっぱりあるもんで
- internetarchive/ia-hadoop-tools
→ あまりお手軽ではない