1. 定义

partititon控制按值分区,并作为map输出的中间产物。键(或键的子集)用于派生分区,通常由哈希函数;分区的总数与reduce任务的数量相同。reduce的数量决定分区数;默认采用的是HashPartititon分区,当reduce个数为1时,采用的不是哈希分区,而是底层自定义的分区,返回值为0。

2. 函数

public int getPartition(K key, V value, int numReduceTasks){

  return (key.hashcode()&Integer.MAX_VALUE)%numReduceTasks; 

}

  -->(key.hashcode()&Integer.MAX_VALUE)

      说明:确保hashCode%numReduceTasks,返回正整数

  -->numReduceTasks为reduce的个数

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-03
  • 2021-08-14
  • 2021-07-31
猜你喜欢
  • 2022-01-07
  • 2021-08-04
  • 2021-12-06
  • 2021-12-25
  • 2021-12-16
  • 2021-11-12
  • 2021-10-12
相关资源
相似解决方案