custom partitioner to send single key to multiple reducers?

411 views Asked by At

If I have only one key. Can I avoid it being sent to only one reducer (and distribute it across multiple reducers)?

I understand that then I might have to have a second map reduce program to combine the reducer outputs? Is this a good approach? Or please let me know if there is a better way?

1

There are 1 answers

4
blackSmith On

I was in a similar situation once. What I did is something like this :

int numberOfReduceCalls = 5
IntWritable outKey = new IntWritable();
Random random = new Random();
public void map(LongWritable key, Text value, Context context)
                      throws IOException, InterruptedException {
    // use a random integer within a limit
    outKey.set( random.nextInt(numberOfReduceCalls) );  
    context.write(outKey, value);
}