Mapreduce之Partition

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值