分区器partition

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的个数

猜你喜欢

转载自www.cnblogs.com/lyr999736/p/9381159.html