4

在我的 map-reduce 作业中,我使用 4 个 reducer 来实现 reducer 作业。因此,通过这样做,最终输出将生成 4 个零件文件。:part-0000 part-0001 part-0002 part-0003

我的问题是如何将 hadoop 的配置设置为只输出一个部分文件,尽管 hadoop 使用 4 个 reducer 工作?

4

2 回答 2

8

这不是 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();
 ...
 }

 }

如果您使用的是新mapreduceAPI,请参见此处

于 2013-03-11T18:52:32.057 回答
-1
MultipleOutputs.addNamedOutput(conf, "text", TextOutputFormat.class,
 LongWritable.class, Text.class);

text是名为的输出目录或单个大文件text

于 2015-11-11T07:25:48.370 回答