MultipleOutputFormat in hadoop
Ich bin ein Neuling in Hadoop. Ich probiere das Wordcount-Programm aus.
Jetzt, um mehrere Ausgabedateien auszuprobieren, verwende ichMultipleOutputFormat
. Dieser Link hat mir dabei geholfen.http: //hadoop.apache.org/common/docs/r0.19.0/api/org/apache/hadoop/mapred/lib/MultipleOutputs.htm
in meiner Fahrerklasse hatte ich
MultipleOutputs.addNamedOutput(conf, "even",
org.apache.hadoop.mapred.TextOutputFormat.class, Text.class,
IntWritable.class);
MultipleOutputs.addNamedOutput(conf, "odd",
org.apache.hadoop.mapred.TextOutputFormat.class, Text.class,
IntWritable.class);`
und meine Reduktionsklasse wurde zu diesem
public static class Reduce extends MapReduceBase implements
Reducer<Text, IntWritable, Text, IntWritable> {
MultipleOutputs mos = null;
public void configure(JobConf job) {
mos = new MultipleOutputs(job);
}
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();
}
if (sum % 2 == 0) {
mos.getCollector("even", reporter).collect(key, new IntWritable(sum));
}else {
mos.getCollector("odd", reporter).collect(key, new IntWritable(sum));
}
//output.collect(key, new IntWritable(sum));
}
@Override
public void close() throws IOException {
// TODO Auto-generated method stub
mos.close();
}
}
Things hat funktioniert, aber ich bekomme VIELE Dateien (eine ungerade und eine gerade für jede Map-Verkleinerung)
Frage ist: Wie kann ich nur 2 Ausgabedateien (ungerade und gerade) haben, so dass jede ungerade Ausgabe jedes Map-Reduces in diese ungerade Datei geschrieben wird, und dasselbe für gerade.