[英]Hadoop is skipping reduce phase entirely
我已经像这样建立了Hadoop工作:
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "Legion");
job.setJarByClass(Legion.class);
job.setMapperClass(CallQualityMap.class);
job.setReducerClass(CallQualityReduce.class);
// Explicitly configure map and reduce outputs, since they're different classes
job.setMapOutputKeyClass(CallSampleKey.class);
job.setMapOutputValueClass(CallSample.class);
job.setOutputKeyClass(NullWritable.class);
job.setOutputValueClass(Text.class);
job.setInputFormatClass(CombineRepublicInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
CombineRepublicInputFormat.setMaxInputSplitSize(job, 128000000);
CombineRepublicInputFormat.setInputDirRecursive(job, true);
CombineRepublicInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.waitForCompletion(true);
}
这项工作完成了,但是发生了一些奇怪的事情。 每条输入线只有一条输出线。 每条输出行CallSampleKey.toString()
方法的输出,选项卡和CallSample@17ab34d
类的CallSample@17ab34d
。
这意味着reduce阶段永远不会运行,并且CallSampleKey
和CallSample
将直接传递到TextOutputFormat
。 但是我不明白为什么会这样。 我已经非常明确地指定了job.setReducerClass(CallQualityReduce.class);
,所以我不知道为什么它会跳过减速器!
编辑:这是减速器的代码:
public static class CallQualityReduce extends Reducer<CallSampleKey, CallSample, NullWritable, Text> {
public void reduce(CallSampleKey inKey, Iterator<CallSample> inValues, Context context) throws IOException, InterruptedException {
Call call = new Call(inKey.getId().toString(), inKey.getUuid().toString());
while (inValues.hasNext()) {
call.addSample(inValues.next());
}
context.write(NullWritable.get(), new Text(call.getStats()));
}
}
如果您尝试更改自己的帐户怎么办
public void reduce(CallSampleKey inKey, Iterator<CallSample> inValues, Context context) throws IOException, InterruptedException {
使用Iterable
代替Iterator
?
public void reduce(CallSampleKey inKey, Iterable<CallSample> inValues, Context context) throws IOException, InterruptedException {
然后,您必须使用inValues.iterator()
来获取实际的迭代器。
如果方法签名不匹配,那么它就属于默认的身份减少器实现 。 不幸的是,底层的默认实现不能使检测这种类型的错字变得容易,但是第二个最好的事情是在打算@Override
的所有方法中始终使用@Override
,以便编译器可以提供帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.