此案例是在MapReduce序列化案例 基础上完成
CustomPartition
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| package flowsum2;
import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Partitioner;
public class CustomPartition extends Partitioner<Text,FlowBean> { @Override public int getPartition(Text text, FlowBean flowBean, int i) { String line=text.toString(); if(line.startsWith("13")){ return 0; }else if(line.startsWith("14")){ return 1; }else if(line.startsWith("15")){ return 2; }else if(line.startsWith("17")){ return 3; }else{ return 4; } } }
|
FlowCountDriver
1 2
| job.setPartitionerClass(CustomPartition.class); job.setNumReduceTasks(5);
|