我有一个 Mapper 类,它给出了一个文本键和IntWritable
值,它可以是 1 二或三。根据值,我必须使用不同的键编写三个不同的文件。我得到一个没有记录的单文件输出。另外,您可以指导我做任何好的多输出示例(带有解释)吗?
我的驱动程序类有这个代码:
MultipleOutputs.addNamedOutput(job, "name", TextOutputFormat.class, Text.class, IntWritable.class);
MultipleOutputs.addNamedOutput(job, "attributes", TextOutputFormat.class, Text.class, IntWritable.class);
MultipleOutputs.addNamedOutput(job, "others", TextOutputFormat.class, Text.class, IntWritable.class);
我的减速机类是:
public static class Reduce extends Reducer<Text, IntWritable, Text, NullWritable> {
private MultipleOutputs mos;
public void setup(Context context) {
mos = new MultipleOutputs(context);
}
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
int sum = 0;
String CheckKey = values.toString();
if("1".equals(CheckKey)) {
mos.write("name", key, new IntWritable(1));
}
else if("2".equals(CheckKey)) {
mos.write("attributes", key, new IntWritable(2));
}
else if("3".equals(CheckKey)) {
mos.write("others", key,new IntWritable(3));
}
/* for (IntWritable val : values) {
sum += val.get();
}*/
//context.write(key, null);
}
@Override
public void cleanup(Context context) throws IOException, InterruptedException {
mos.close();
}
}
PS 我是 HADOOP/MAP-Reduce 编程的新手。