大数据mapreduceWritableComparable分区内排序案例
小贾嗯嗯此案例是在 WritableComparable全排序案例 基础上完成
FlowBean
1 2 3 4 5 6 7 8 9 10 11 12
| public class FlowBean implements WritableComparable<FlowBean> { ······ @Override public int compareTo(FlowBean o) { if(this.sumFlow!=o.getSumFlow()) { return this.sumFlow > o.getSumFlow() ? -1 : 1; }else { return 0; } } ······ }
|
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);
|