在我的 map-reduce 作业中,我使用 4 个 reducer 来实现 reducer 作业。因此,通过这样做,最终输出将生成 4 个零件文件。:part-0000 part-0001 part-0002 part-0003
我的问题是如何将 hadoop 的配置设置为只输出一个部分文件,尽管 hadoop 使用 4 个 reducer 工作?
在我的 map-reduce 作业中,我使用 4 个 reducer 来实现 reducer 作业。因此,通过这样做,最终输出将生成 4 个零件文件。:part-0000 part-0001 part-0002 part-0003
我的问题是如何将 hadoop 的配置设置为只输出一个部分文件,尽管 hadoop 使用 4 个 reducer 工作?
这不是 hadoop 所期望的行为。但是你可以MultipleOutputs
在这里发挥你的优势。创建一个命名输出并在所有 reducer 中使用它来在一个文件本身中获取最终输出。它的 javadoc 本身建议如下:
JobConf conf = new JobConf();
conf.setInputPath(inDir);
FileOutputFormat.setOutputPath(conf, outDir);
conf.setMapperClass(MOMap.class);
conf.setReducerClass(MOReduce.class);
...
// Defines additional single text based output 'text' for the job
MultipleOutputs.addNamedOutput(conf, "text", TextOutputFormat.class,
LongWritable.class, Text.class);;
...
JobClient jc = new JobClient();
RunningJob job = jc.submitJob(conf);
...
作业配置使用模式是:
public class MOReduce implements
Reducer<WritableComparable, Writable> {
private MultipleOutputs mos;
public void configure(JobConf conf) {
...
mos = new MultipleOutputs(conf);
}
public void reduce(WritableComparable key, Iterator<Writable> values,
OutputCollector output, Reporter reporter)
throws IOException {
...
mos.getCollector("text", reporter).collect(key, new Text("Hello"));
...
}
public void close() throws IOException {
mos.close();
...
}
}
如果您使用的是新mapreduce
API,请参见此处。
MultipleOutputs.addNamedOutput(conf, "text", TextOutputFormat.class,
LongWritable.class, Text.class);
这text
是名为的输出目录或单个大文件text
?