[英]How do I set the numReduceTask for custom Partitioner in the case of custom key
HashPartitioner<Text,Text> hash=new HashPartitioner<Text,Text>();
@Override
public int getPartition(CompositeKeyClass keyClass, Text valClass, int numOfPartition) {
// TODO Auto-generated method stub
try {
String[] type=valClass.toString().split(",");
if(type[0].equals("Mapper1")) {
return (hash.getPartition(keyClass.getFirst(), valClass, numOfPartition))%numOfPartition;
} else {
return (hash.getPartition(keyClass.getFirst(), valClass, numOfPartition))%numOfPartition;
}
}
}
I am using the above code in the Partitioner class to get the key for my custom class. 我在Partitioner类中使用上面的代码来获取自定义类的密钥。 All works fine but I want that the value that has the text "Mapper1" sent to first reducer and the other one sent to second.
一切正常,但我希望将具有文本“ Mapper1”的值发送到第一个reducer,将另一个发送到第二个reduce。 How can I achieve that?
我该如何实现? I have set
job.numOfReduceTaks
to 2. Please help! 我已将
job.numOfReduceTaks
设置为2。请帮助!
This is a static decision right? 这是静态决定吧? Try this:
尝试这个:
if (type[0].equals("Mapper1")) {
return 0;
} else {
return 1;
}
And yes, in driver you need to set job.numOfReduceTaks
to 2. You did it right. 是的,在驱动程序中,您需要将
job.numOfReduceTaks
设置为2。您做对了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.