我有簡單的map/reduce實現。 Mapper被調用,它完成它的工作,但是reducer永遠不會被調用。
這裏是映射:
static public class InteractionMap extends Mapper<LongWritable, Text, Text, InteractionWritable> {
@Override
protected void map(LongWritable offset, Text text, Context context) throws IOException, InterruptedException {
System.out.println("mapper");
String[] tokens = text.toString().split(",");
for (int idx = 0; idx < tokens.length; idx++) {
String sourceUser = tokens[1];
String targetUser = tokens[2];
int points = Integer.parseInt(tokens[4]);
context.write(new Text(sourceUser), new InteractionWritable(targetUser, points));
}
}
}
}
這裏是我的減速器:
static public class InteractionReduce extends Reducer<Text, InteractionWritable, Text, Text> {
@Override
protected void reduce(Text token, Iterable<InteractionWritable> counts, Context context) throws IOException, InterruptedException {
System.out.println("REDUCER");
Iterator<InteractionWritable> i = counts.iterator();
while (i.hasNext()) {
InteractionWritable interaction = i.next();
context.write(token, new Text(token.toString() + " " + interaction.getTargetUser().toString() + " " + interaction.getPoints().get()));
}
}
}
而且,這裏是配置部分:
@Override
public int run(String[] args) throws Exception {
Configuration configuration = getConf();
Job job = new Job(configuration, "Interaction Count");
job.setJarByClass(InteractionMapReduce.class);
job.setMapperClass(InteractionMap.class);
job.setCombinerClass(InteractionReduce.class);
job.setReducerClass(InteractionReduce.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
return job.waitForCompletion(true) ? 0 : -1;
}
沒有人有任何想法,爲什麼減速不被調用?
你能分享你的計數器的地圖,合併器和減速器輸入/輸出計數? –