Partition了解
Partition位置
Partition主要作用就是将map的结果发送到相应的reduce。这就对partition有两个要求:
1)均衡负载,尽量的将工作均匀的分配给不同的reduce。
2)效率,分配速度一定要快。
patition类结构
1. Partitioner是partitioner的基类,如果需要定制partitioner也需要继承该类。
2. HashPartitioner是mapreduce的默认partitioner。计算方法是
which reducer=(key.hashCode() & Integer.MAX_VALUE) % numReduceTasks,得到当前的目的reducer。
需求:
需求1:根据高考数据计算 一本 二本 专科 未录取的数据,并分别输出
数据:
东城区 东城区第1中学 盖谦 2001-01-14 11480630 540
东城区 东城区第1中学 笪艳 2001-03-06 11720510 480
东城区 东城区第1中学 暨寒 2002-06-26 11391225 443
东城区 东城区第1中学 车世琛 2002-04-22 11883106 458
东城区 东城区第1中学 韶梦英 1998-08-04 11554719 130
东城区 东城区第1中学 加思 2000-12-28 11788401 454
东城区 东城区第1中学 墨琳娅 2001-07-21 11340297 424
东城区 东城区第1中学 雍山伟 1999-02-06 11928178 397
代码:
package com.hnxy.mr.Sort;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Partitioner;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import com.hnxy.mr.Sort.SortMr3.SortMrMapper;
/**
*
* @author 耀君
*
*
*/
public class PartitionDataMR extends Configured implements Tool {
// 东城区 东城区第1中学 盖谦 2001-01-14 11480630 540
private static class PartitionDataMRMapper extends Mapper<LongWritable, Text, Tex