gpt4 book ai didi

hadoop - 当 reducer 的输出 VALUE 为 null 时,如何使用 combiner?

转载 作者:可可西里 更新时间:2023-11-01 16:48:35 25 4
gpt4 key购买 nike

当我尝试在我的 MR 作业中使用组合器时,出现以下异常

java.lang.NullPointerException
at org.apache.hadoop.mapred.IFile$Writer.append(IFile.java:193)
at org.apache.hadoop.mapred.Task$CombineOutputCollector.collect(Task.java:1315)

at org.apache.hadoop.mapred.Task$NewCombinerRunner$OutputConverter.write(Task.java:1632)

原因是,我在 reducer 类中使用 null 作为我的输出值。 reducer 代码:

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);
}
}

当我删除组合器类时 job.setCombinerClass(reducer.class); 作业成功了。

我如何实现组合器,我需要相同的 reducer 输出,即只有 KEY 作为输出?

最佳答案

这是不可能实现的。问题是 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);

.....

append()函数中,有一个检查:

if (value.getClass() != valueClass)

由于您将 null 作为值传递,因此当它尝试对 执行 getClass() 时,将抛出 NullPointerException 值:

value.getClass()

因此,即使您使用 NullWritable(同样是一个类)并传递 null,您仍然会得到 NullPointerException

您应该通过传递 0(零)来管理,而不是传递 null

关于hadoop - 当 reducer 的输出 VALUE 为 null 时,如何使用 combiner?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34480634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com