Class BinaryPartitioner<V>
java.lang.Object
org.apache.hadoop.mapreduce.Partitioner<BinaryComparable,V>
org.apache.hadoop.mapreduce.lib.partition.BinaryPartitioner<V>
- All Implemented Interfaces:
Configurable
- Direct Known Subclasses:
BinaryPartitioner
@Public
@Evolving
public class BinaryPartitioner<V>
extends Partitioner<BinaryComparable,V>
implements Configurable
Partition BinaryComparable keys using a configurable part of
the bytes array returned by BinaryComparable.getBytes().
The subarray to be used for the partitioning can be defined by means of the following properties:
- mapreduce.partition.binarypartitioner.left.offset: left offset in array (0 by default)
- mapreduce.partition.binarypartitioner.right.offset: right offset in array (-1 by default)
+---+---+---+---+---+
| B | B | B | B | B |
+---+---+---+---+---+
0 1 2 3 4
-5 -4 -3 -2 -1
The first row of numbers gives the position of the offsets 0...5 in
the array; the second row gives the corresponding negative offsets.
Contrary to Python, the specified subarray has byte i
and j as first and last element, repectively, when
i and j are the left and right offset.
For Hadoop programs written in Java, it is advisable to use one of the following static convenience methods for setting the offsets:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetConf()Return the configuration used by this object.intgetPartition(BinaryComparable key, V value, int numPartitions) Use (the specified slice of the array returned by)BinaryComparable.getBytes()to partition.voidsetConf(Configuration conf) Set the configuration to be used by this object.static voidsetLeftOffset(Configuration conf, int offset) Set the subarray to be used for partitioning tobytes[offset:]in Python syntax.static voidsetOffsets(Configuration conf, int left, int right) Set the subarray to be used for partitioning tobytes[left:(right+1)]in Python syntax.static voidsetRightOffset(Configuration conf, int offset) Set the subarray to be used for partitioning tobytes[:(offset+1)]in Python syntax.
-
Field Details
-
LEFT_OFFSET_PROPERTY_NAME
- See Also:
-
RIGHT_OFFSET_PROPERTY_NAME
- See Also:
-
-
Constructor Details
-
BinaryPartitioner
public BinaryPartitioner()
-
-
Method Details
-
setOffsets
Set the subarray to be used for partitioning tobytes[left:(right+1)]in Python syntax.- Parameters:
conf- configuration objectleft- left Python-style offsetright- right Python-style offset
-
setLeftOffset
Set the subarray to be used for partitioning tobytes[offset:]in Python syntax.- Parameters:
conf- configuration objectoffset- left Python-style offset
-
setRightOffset
Set the subarray to be used for partitioning tobytes[:(offset+1)]in Python syntax.- Parameters:
conf- configuration objectoffset- right Python-style offset
-
setConf
Description copied from interface:ConfigurableSet the configuration to be used by this object.- Specified by:
setConfin interfaceConfigurable- Parameters:
conf- configuration to be used
-
getConf
Description copied from interface:ConfigurableReturn the configuration used by this object.- Specified by:
getConfin interfaceConfigurable- Returns:
- Configuration
-
getPartition
Use (the specified slice of the array returned by)BinaryComparable.getBytes()to partition.- Specified by:
getPartitionin classPartitioner<BinaryComparable,V> - Parameters:
key- the key to be partioned.value- the entry value.numPartitions- the total number of partitions.- Returns:
- the partition number for the
key.
-