Class HashPartitioner

  • All Implemented Interfaces:

    public final class HashPartitioner
    extends Object
    implements Partitioner<Integer>
    An implementation of Partitioner which hashes output data from a source task according to the key of elements. The data will be hashed by their key, and applied "modulo" operation by the number of partitions.
    • Constructor Detail

      • HashPartitioner

        public HashPartitioner​(int numOfPartitions,
                               KeyExtractor keyExtractor)
        numOfPartitions - the number of partitions.
        keyExtractor - the key extractor that extracts keys from elements.
    • Method Detail

      • partition

        public Integer partition​(Object element)
        Description copied from interface: Partitioner
        Divides the output data from a task into multiple blocks.
        Specified by:
        partition in interface Partitioner<Integer>
        element - the output element from a source task.
        the key of the partition in the block to write the element.