在我的map-reduce作业中,我使用4个reducer来实现reducer作业。因此,通过这样做,最终输出将生成4个部分文件:part-0000 part-0001 part-0002 part-0003
我的问题是如何将hadoop的配置设置为仅输出一个零件文件,尽管hadoop使用4个Reducer工作?
答案 0 :(得分:8)
这不是hadoop所期望的行为。但是你可以在这里使用MultipleOutputs
。
创建一个命名输出并在所有reducers中使用它以在一个文件本身中获得最终输出。这是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,请参阅here。
答案 1 :(得分:-1)
MultipleOutputs.addNamedOutput(conf, "text", TextOutputFormat.class,
LongWritable.class, Text.class);
此处text
是输出目录或名为text
的单个大文件?