Hadoop中的自定义分区错误java.lang.NoSuchMethodException: - <init>()

时间:2018-04-20 14:59:07

标签: java hadoop hadoop-partitioning

我正在尝试创建一个自定义分区程序,以将每个唯一键分配给单个reducer。这是在默认的 HashPartioner 失败之后 Alternative to the default hashpartioner provided with hadoop

我一直收到以下错误。它与构造函数没有接收到它的参数有关,我可以从做一些研究中得知。但在这种情况下,使用hadoop,不是框架自动传递的参数吗?我无法在代码中找到错误

18/04/20 17:06:51 INFO mapred.JobClient: Task Id : attempt_201804201340_0007_m_000000_1, Status : FAILED
java.lang.RuntimeException: java.lang.NoSuchMethodException: biA3pipepart$parti.<init>()
    at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:131)
    at org.apache.hadoop.mapred.MapTask$NewOutputCollector.<init>(MapTask.java:587)

这是我的分区:

 public class Parti extends Partitioner<Text, Text> {
    String partititonkey;
    int result=0;
    @Override
    public int getPartition(Text key, Text value, int numPartitions) {


 String partitionKey = key.toString();

     if(numPartitions >= 9){
               if(partitionKey.charAt(0) =='0' ){
        if(partitionKey.charAt(2)=='0' )
                result= 0;
        else
        if(partitionKey.charAt(2)=='1' )
                result= 1;
        else
                result= 2;
             }else

        if(partitionKey.charAt(0)=='1'){
        if(partitionKey.charAt(2)=='0' )
                result= 3;
        else
        if(partitionKey.charAt(2)=='1' )
                result= 4;
        else
                result= 5;
             }else
        if(partitionKey.charAt(0)=='2' ){
        if(partitionKey.charAt(2)=='0' )
                result= 6;
        else
            if(partitionKey.charAt(2)=='1' )
                    result= 7;
            else
                    result= 8;
             }


        } //
    else

            result= 0; 

   return result;
}// close method
}// close class

我的映射器签名

public static class JoinsMap extends Mapper<LongWritable,Text,Text,Text>{
    public void Map(LongWritable key, Text value, Context context) throws IOException, InterruptedException{

我的减速机标志

public static class JoinsReduce extends Reducer<Text,Text,Text,Text>{
public void Reduce (Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {

主要课程:

public static void main( String[] args ) throws Exception {




     Configuration conf1 = new Configuration();


     Job job1 = new Job(conf1, "biA3pipepart");

    job1.setJarByClass(biA3pipepart.class);

    job1.setNumReduceTasks(9);//***


     job1.setOutputKeyClass(Text.class);
     job1.setOutputValueClass(Text.class);

     job1.setMapperClass(JoinsMap.class);
     job1.setReducerClass(JoinsReduce.class);

     job1.setInputFormatClass(TextInputFormat.class);
     job1.setOutputFormatClass(TextOutputFormat.class);

    job1.setPartitionerClass(Parti.class); //+++
    // inputs to  map.
        FileInputFormat.addInputPath(job1, new Path(args[0]));   

     // single output from reducer.
     FileOutputFormat.setOutputPath(job1, new Path(args[1]));

     job1.waitForCompletion(true);


}
Mapper发出的

键如下:

0,0
0,1
0,2
1,0
1,1
1,2
2,0
2,1
2,2

并且Reducer仅写入它接收的键和值。

1 个答案:

答案 0 :(得分:1)

解决

我刚刚将static添加到我的Parti类,就像注释(user238607)所建议的mapper和reducer类一样。

public static class Parti extends Partitioner<Text, Text> {