Hadoop mapreduce 中partition作用

1.其中mapreduce中map输出的数据会根据不同的key输入到不同的reduce,是怎么判断不同key输入到不同的reduce的呢?

就是通过partition,在缺省的情况下默认HashPartitioner,它通过对key取hash值,然后与reduce的数目取模,然后就可以判断该key及对应的valuelist应该去哪个reduce上进行处理。


<span style="font-size:14px;">public interface Partitioner<K2, V2> extends JobConfigurable {
  /** 
   * Get the paritition number for a given key (hence record) given the total 
   * number of partitions i.e. number of reduce-tasks for the job.
   *   
   * <p>Typically a hash function on a all or a subset of the key.</p>
   *
   * @param key the key to be paritioned.
   * @param value the entry value.
   * @param numPartitions the total number of partitions.
   * @return the partition number for the <code>key</code>.
   */
  int getPartition(K2 key, V2 value, int numPartitions);
}</span>
Hadoop将会根据getPartitioner返回的值判断mapper的值将会被发到哪个reducer上,返回值相同的Key/value将会被输出到同一个reducer上。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值