如果您使用Pig版本0.10.0或更高版本,则可以利用source tagging和MultiStorage的组合来跟踪这些文件。
例如,如果您有相关的文件和内容如下输入目录pigin
:
pigin
|-test1 => "hello"
|-test2 => "world"
|-test3 => "Apache"
|-test4 => "Hadoop"
|-test5 => "Pig"
下面的脚本将读取每个脚本的每个文件的内容写入到不同的目录。
%declare inputPath 'pigin'
%declare outputPath 'pigout'
-- Define MultiStorage to write output to different directories based on the
-- first element in the tuple
define MultiStorage org.apache.pig.piggybank.storage.MultiStorage('$outputPath','0');
-- Load the input files, prepending each tuple with the file name
A = load '$inputPath' using PigStorage(',', '-tagsource');
-- Write output to different directories
store A into '$outputPath' using MultiStorage();
以上脚本将创建看起来像以下内容的输出目录树:
pigout
|-test1
| `-test1-0 => "test1 hello"
|-test2
| `-test2-0 => "test2 world"
|-test3
| `-test3-0 => "test3 Apache"
|-test4
| `-test4-0 => "test4 Hadoop"
|-test5
| `-test5-0 => "test5 Pig"
的-0
在文件名的末尾对应于所产生的输出的减速器。如果您有多个reducer,则每个目录可能会看到多个文件。
谢谢alexeipab。链接看起来很有趣。 但是,如何在Java中使用嵌入式Pig工作?有什么想法吗。 – Uno 2012-07-12 17:01:03