Hadoop:在MapReduce期间OutputCollector如何工作?

cat*_*tty 9 java hadoop mapreduce

我想知道OutputCollector的'实例'输出是否在map函数中使用:output.collect(key,value)this -output-在某处存储键值对?即使它发送到reducer函数,它们也必须是一个中间文件,对吧?那些文件是什么?它们是否可见并由程序员决定?我们在main函数中指定的OutputKeyClass和OutputValueClasses这些存储位置是什么?[Text.class和IntWritable.class]

我在MapReduce中给出了Word Count示例的标准代码,我们可以在网络的许多地方找到它.

public class WordCount {

public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();

public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
output.collect(word, one);
}
}
}

public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
int sum = 0;
while (values.hasNext()) {
sum += values.next().get();
}
output.collect(key, new IntWritable(sum));
}
}

public static void main(String[] args) throws Exception {
JobConf conf = new JobConf(WordCount.class);
conf.setJobName("wordcount");

conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);

conf.setMapperClass(Map.class);
conf.setCombinerClass(Reduce.class);
conf.setReducerClass(Reduce.class);

conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);

FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));    
JobClient.runJob(conf);
}
}
Run Code Online (Sandbox Code Playgroud)

Uli*_*ses 2

我相信它们存储在临时位置并且开发人员无法使用,除非您创建自己的实现OutputCollector.

我曾经不得不访问这些文件并通过创建副作用文件解决了问题: http://hadoop.apache.org/common/docs/r0.20.2/mapred_tutorial.html#Task+Side-Effect+Files