我正在使用MapReduce框架在Java中制作Hadoop应用程序。两个相等的组合键不会达到相同的缩减器
我只使用文本键和输入和输出值。在减少到最终输出之前,我使用组合器来执行额外的计算步骤。
但我有问题,键不会去相同的减速机。 创建并添加键/值对像这样在组合:
public static class Step4Combiner extends Reducer<Text,Text,Text,Text> {
private static Text key0 = new Text();
private static Text key1 = new Text();
public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
key0.set("KeyOne");
key1.set("KeyTwo");
context.write(key0, new Text("some value"));
context.write(key1, new Text("some other value"));
}
}
public static class Step4Reducer extends Reducer<Text,Text,Text,Text> {
public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
System.out.print("Key:" + key.toString() + " Value: ");
String theOutput = "";
for (Text val : values) {
System.out.print("," + val);
}
System.out.print("\n");
context.write(key, new Text(theOutput));
}
}
在主我创建这样的作业:
Configuration conf = new Configuration();
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
Job job4 = new Job(conf, "Step 4");
job4.setJarByClass(Step4.class);
job4.setMapperClass(Step4.Step4Mapper.class);
job4.setCombinerClass(Step4.Step4Combiner.class);
job4.setReducerClass(Step4.Step4Reducer.class);
job4.setInputFormatClass(TextInputFormat.class);
job4.setOutputKeyClass(Text.class);
job4.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(job4, new Path(outputPath));
FileOutputFormat.setOutputPath(job4, new Path(finalOutputPath));
System.exit(job4.waitForCompletion(true) ? 0 : 1);
在标准输出的输出从减速器印刷是这样的:
Key:KeyOne Value: ,some value
Key:KeyTwo Value: ,some other value
Key:KeyOne Value: ,some value
Key:KeyTwo Value: ,some other value
Key:KeyOne Value: ,some value
Key:KeyTwo Value: ,some other value
这是没有意义的,因为密钥是相同的,因此,它应该是2个减速与它相同的值的3是可迭代
希望你能帮助我得到这条底线:)
,如果你把我们的完整代码这将帮助;)当看到这里的代码片段,它看起来不错。问题在其他地方我相信。 – Amar
您是否使用与您的组合器以及减速器相同的类? – Amar
我添加了整个组合器和减速器,这些都是虚拟的,只是为了将问题展示在最低限度。 – Bjarkes