gpt4 book ai didi

java - Partitioner 类型的 getPartition 的名称冲突在 MapReduce、Hadoop 中具有相同类型主类的删除

转载 作者:可可西里 更新时间:2023-11-01 15:54:16 29 4
gpt4 key购买 nike

我正在尝试编写一个代码,我可以根据字符的长度自定义输入将转到 reducer,使用实现到默认 Mapper 和 Reducer 的分区,但出现以下错误。我会感谢帮助我的人。

int setNumRedTasks) 错误:

Name clash: The method getPartition(Object, Object, int) of type MyPartitioner has the same erasure as getPartition(K2, V2, int) of type Partitioner but does not override it

代码:

package partition;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.Partitioner;

public abstract class MyPartitioner implements Partitioner<Text, IntWritable>{

@Override
public void configure(JobConf arg0) {
// TODO Auto-generated method stub

}
// @Override
public int getPartition(Object key, Object value, int setNumRedTasks) {
String s = key.toString();
if(s.length()==1)
{
return 0;
}

if(s.length()==2)
{
return 1;
}

if(s.length()==3)
{
return 2;
}
else
return 3;


}
}

最佳答案

您的getPartition 方法签名有误,需要:

public int getPartition(Text key, IntWritable value, int setNumRedTasks) {
... Code goes here
}

这个 SO 答案解释了删除错误的含义:Method has the same erasure as another method in type

实际上,因为您使用的是 Object 而不是泛型类型,所以无法确定要使用哪个版本,它们是等价的。

关于java - Partitioner 类型的 getPartition 的名称冲突在 MapReduce、Hadoop 中具有相同类型主类的删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45952814/

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