0

I want to use the value of IntWritable as the condition to partition data. But it seems Partitioner() can not get value.

public static class GroupMapper extends Mapper<Object, Text, Text, IntWritable>
{               
    public void map(Object index, Text value, Context context) throws IOException, InterruptedException 
    {
        String[] words=value.toString().split(" ");
        for(int i=0;i<words.length-1;i++) 
        {
            context.write(new Text(words[i]), new IntWritable(Integer.parseInt(words[words.length-1])));            
        }   
    }

}

public static class RatingPartitioner extends Partitioner<Text, IntWritable>
{
    public int getPartition(Text key, IntWritable value, int numReduceTasks)
    {  
        int group=value.get();
        if(numReduceTasks==0) {return 0;}
        else if(group==1) {return 0;}
        else if(group==2) {return 1;}
        else if(group==3) {return 2;}
        else {return 3;}
    }
 }

When I run the code. Java shows NullPointerException. How can I fix the code?

yyyyyyrc
  • 21
  • 3

1 Answers1

0

3 things are possible but since i don't have the code that launches those functions i'll say them all XD Either:

In the first function :

the parameter 'value' is null and it causes a NullPointerException when 
trying to do : value.toString

the parameter 'context' is null and it causes a NullPointerException 
when trying to do : context.write

In the second function :

the parameter 'value' is null and it causes a NullPointerException when 
trying to do : value.get()
cobrius
  • 161
  • 12