Tôi là người mới trong Hadoop. Tôi đang thử chương trình Wordcount.MultipleOutputFormat in hadoop
Bây giờ để thử nhiều tệp đầu ra, tôi sử dụng MultipleOutputFormat
. liên kết này đã giúp tôi làm điều đó. http://hadoop.apache.org/common/docs/r0.19.0/api/org/apache/hadoop/mapred/lib/MultipleOutputs.html
trong lớp học lái xe của tôi đã
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);`
và tôi giảm lớp trở này
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();
}
}
Những điều làm việc, nhưng tôi nhận được rất nhiều các tác phẩm, (một số lẻ và một ngay cả đối với mỗi bản đồ -reduce)
Câu hỏi là: Làm cách nào tôi có thể chỉ có 2 tệp đầu ra (lẻ & thậm chí) sao cho mỗi đầu ra lẻ của mỗi bản đồ giảm được ghi vào số lẻ đó và thậm chí là cả.
Bạn đang sử dụng MultipleOutputs không MultipleOutputFormat. Cả hai đều là các thư viện khác nhau. –