WordCount partitioner


2 Answer(s)


Found the problem.

In the code, the else part was returning 3. It should return 2

/* Code with error */

public int getPartition(Text key, IntWritable value, int numPartitions) {

String myKey = key.toString().toLowerCase();

if (myKey.equals("hadoop")) {
return 0;
}
if (myKey.equals("data")) {
return 1;
} else {
return 3;
}
}

/* Fixed code */

public int getPartition(Text key, IntWritable value, int numPartitions) {

String myKey = key.toString().toLowerCase();

if (myKey.equals("hadoop")) {
return 0;
}
if (myKey.equals("data")) {
return 1;
} else {
return 2;
}
}

Thanks for the update Chi