How does HashPartitioner work?

后端 未结 3 1816
面向向阳花
面向向阳花 2020-11-22 14:56

I read up on the documentation of HashPartitioner. Unfortunately nothing much was explained except for the API calls. I am under the assumption that HashPartitioner

3条回答
  •  粉色の甜心
    2020-11-22 15:48

    The HashPartitioner.getPartition method takes a key as its argument and returns the index of the partition which the key belongs to. The partitioner has to know what the valid indices are, so it returns numbers in the right range. The number of partitions is specified through the numPartitions constructor argument.

    The implementation returns roughly key.hashCode() % numPartitions. See Partitioner.scala for more details.

提交回复
热议问题