简体   繁体   English

类型分区器的getPartition的名称冲突在MapReduce,Hadoop中具有与类型主类相同的擦除

[英]Name clash of getPartition of type Partitioner has the same erasure of type main class in MapReduce, Hadoop

I was trying to write a code that I can customize the Input will go to the reducer according to the length of the character using implementing to the Partition where default Mapper and Reducer, but the following error is coming. 我试图编写一个可以自定义输入的代码,然后使用实现到默认Mapper和Reducer的分区来根据字符的长度输入到reducer,但是会出现以下错误。 I will be thankful to someone who will help me. 我将感谢能帮助我的人。

Error in int setNumRedTasks) : int setNumRedTasks)错误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 名称冲突:MyPartitioner类型的getPartition(Object,Object,int)方法与Partitioner类型的getPartition(K2,V2,int)具有相同的擦除,但不会覆盖它

Code: 码:

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;


    }
}

Your getPartition method signature is wrong, it need to be: 您的getPartition方法签名是错误的,它必须是:

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

This SO answer explains what the erasure error means: Method has the same erasure as another method in type 该SO答案说明了擦除错误的含义: 方法与类型中的另一种方法具有相同的擦除

Effectively, because you used Object instead of the generic types it can't work out which version to use, they are equivalent. 实际上,由于使用Object而不是泛型类型,因此无法确定要使用哪个版本,因此它们是等效的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM