类型 Partitioner 的 getPartition 的名称冲突在 MapReduce、Hadoop 中具有相同类型 main class 的擦除
Name clash of getPartition of type Partitioner has the same erasure of type main class in MapReduce, Hadoop
我正在尝试编写一个代码,我可以根据字符的长度自定义输入将转到 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 而不是泛型类型,所以无法确定要使用哪个版本,它们是等效的。
我正在尝试编写一个代码,我可以根据字符的长度自定义输入将转到 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 而不是泛型类型,所以无法确定要使用哪个版本,它们是等效的。