Class RangePartitioner<T>

  • All Implemented Interfaces:
    Partitioner<T>
    Direct Known Subclasses:
    LongRangePartitioner

    public class RangePartitioner<T>
    extends Object
    implements Partitioner<T>
    A partitioner which assumes that the keys are sorted in increasing order.
    Author:
    Antonin Delpeuch
    • Field Detail

      • numPartitions

        protected final int numPartitions
      • firstKeys

        protected final List<T> firstKeys
    • Constructor Detail

      • RangePartitioner

        public RangePartitioner​(int nbPartitions,
                                List<T> firstKeys,
                                Comparator<T> comparator)
        Constructs a partitioner by supplying the first key value in each partition but the first one.
        Parameters:
        nbPartitions - the number of partitions of the PLL this partitioner is built for
        firstKeys - list of (n-1) values, where n is the number of partitions. The first element of the list is the first key value in the second partition. If a partition is empty, null is used.
        comparator - the comparator used to compare the keys
    • Method Detail

      • getPartition

        public int getPartition​(T key)
        Description copied from interface: Partitioner
        Retrieves the partition id given a key.
        Specified by:
        getPartition in interface Partitioner<T>
        Returns:
      • numPartitions

        public int numPartitions()
        Description copied from interface: Partitioner
        Returns the number of partitions assumed by this partitioner.
        Specified by:
        numPartitions in interface Partitioner<T>
      • getFirstKeys

        public List<Optional<T>> getFirstKeys()
        List of (n-1) values, where n is the number of partitions. The first element of the list is the first key value in the second partition. If a partition is empty, no value is returned.