[英]How to use combiner, when the output VALUE of reducer is null?
When I tried to use combiner in my MR job I am getting the below exception 当我尝试在MR工作中使用合并器时,出现以下异常
java.lang.NullPointerException
java.lang.NullPointerException
at org.apache.hadoop.mapred.IFile$Writer.append(IFile.java:193)在org.apache.hadoop.mapred.IFile $ Writer.append(IFile.java:193)
at org.apache.hadoop.mapred.Task$CombineOutputCollector.collect(Task.java:1315)在org.apache.hadoop.mapred.Task $ CombineOutputCollector.collect(Task.java:1315)
at org.apache.hadoop.mapred.Task$NewCombinerRunner$OutputConverter.write(Task.java:1632)
在org.apache.hadoop.mapred.Task $ NewCombinerRunner $ OutputConverter.write(Task.java:1632)
The reason is, I am using null as my output VALUE in reducer class. 原因是,我在还原器类中将null用作输出值。 Reducer Code :
减速器代码:
public static class reducer extends Reducer<Text,IntWritable,Text,IntWritable>{
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException{
context.write(key, null);
}
}
When I remove the combiner class job.setCombinerClass(reducer.class); 当我删除组合器类job.setCombinerClass(reducer.class); job is getting successful.
工作取得成功。
How can I implement combiner, I need the same reducer output ie with only KEY as output? 如何实现合并器,我需要相同的reducer输出,即仅KEY作为输出?
This is not possible to achieve. 这是不可能实现的。 The problem is the following piece of code in IFile.java :
问题是IFile.java中的以下代码:
public void append(K key, V value) throws IOException {
.....
if (value.getClass() != valueClass)
throw new IOException("wrong value class: "+ value.getClass()
+" is not "+ valueClass);
.....
In the append()
function, there is a check: 在
append()
函数中,有一个检查:
if (value.getClass() != valueClass)
Since you are passing null
as the value, the NullPointerException
is thrown, when it tries to getClass()
on a null
value: 由于您要传递
null
作为值,因此当它尝试对null
值进行getClass()
时,将抛出NullPointerException
:
value.getClass()
So, even if you use NullWritable
(which is again a class) and pass null
, you will still get the NullPointerException
. 因此,即使您使用
NullWritable
(这又是一个类)并传递null
,您仍然会得到NullPointerException
。
Instead of passing null
, you should manage by passing 0 (Zero). 而不是传递
null
,您应该通过传递0(零)进行管理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.