14/08/01 15:21:03 INFO mapred.JobClient: Task Id : attempt_201408011020_0012_m_000002_0, Status : FAILED
java.io.IOException: Illegal partition for 26 (-1)
at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.collect(MapTask.java:1078)
at org.apache.hadoop.mapred.MapTask$NewOutputCollector.write(MapTask.java:690)
at org.apache.hadoop.mapreduce.TaskInputOutputContext.write(TaskInputOutputContext.java:80)
at com.hadoop.examples.Sort$Map.map(Sort.java:32)
at com.hadoop.examples.Sort$Map.map(Sort.java:1)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:764)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:364)
at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1190)
at org.apache.hadoop.mapred.Child.main(Child.java:249)java
/**
* 自定義Partition函數,此函數根據輸入數據的最大值和MapReduce框架中
* Partition的數量獲取將輸入數據安裝大小分塊的邊界,而後根據輸入數據和邊界的關係
* 返回對象Partition ID
*/
public static class Partition extends Partitioner<IntWritable, IntWritable>
{
@Override
public int getPartition(IntWritable key, IntWritable value, int numPartitions)
{
int maxNumber = 65223;
int bound = maxNumber / numPartitions + 1;
int keyNumber = key.get();
for(int i = 0; i < numPartitions; i++)
{
if(keyNumber < bound * i && keyNumber >= bound * (i - 1))
{
return i - 1;
}
}
// return 0;
return -1;
}
}apache