@InterfaceAudience.Public @InterfaceStability.Evolving public class BinaryPartitioner<V> extends Partitioner<org.apache.hadoop.io.BinaryComparable,V> implements org.apache.hadoop.conf.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:
+---+---+---+---+---+
| 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:
| Modifier and Type | Field and Description |
|---|---|
static String |
LEFT_OFFSET_PROPERTY_NAME |
static String |
RIGHT_OFFSET_PROPERTY_NAME |
| Constructor and Description |
|---|
BinaryPartitioner() |
| Modifier and Type | Method and Description |
|---|---|
org.apache.hadoop.conf.Configuration |
getConf() |
int |
getPartition(org.apache.hadoop.io.BinaryComparable key,
V value,
int numPartitions)
Use (the specified slice of the array returned by)
BinaryComparable.getBytes() to partition. |
void |
setConf(org.apache.hadoop.conf.Configuration conf) |
static void |
setLeftOffset(org.apache.hadoop.conf.Configuration conf,
int offset)
Set the subarray to be used for partitioning to
bytes[offset:] in Python syntax. |
static void |
setOffsets(org.apache.hadoop.conf.Configuration conf,
int left,
int right)
Set the subarray to be used for partitioning to
bytes[left:(right+1)] in Python syntax. |
static void |
setRightOffset(org.apache.hadoop.conf.Configuration conf,
int offset)
Set the subarray to be used for partitioning to
bytes[:(offset+1)] in Python syntax. |
public static final String LEFT_OFFSET_PROPERTY_NAME
public static final String RIGHT_OFFSET_PROPERTY_NAME
public static void setOffsets(org.apache.hadoop.conf.Configuration conf,
int left,
int right)
bytes[left:(right+1)] in Python syntax.conf - configuration objectleft - left Python-style offsetright - right Python-style offsetpublic static void setLeftOffset(org.apache.hadoop.conf.Configuration conf,
int offset)
bytes[offset:] in Python syntax.conf - configuration objectoffset - left Python-style offsetpublic static void setRightOffset(org.apache.hadoop.conf.Configuration conf,
int offset)
bytes[:(offset+1)] in Python syntax.conf - configuration objectoffset - right Python-style offsetpublic void setConf(org.apache.hadoop.conf.Configuration conf)
setConf in interface org.apache.hadoop.conf.Configurablepublic org.apache.hadoop.conf.Configuration getConf()
getConf in interface org.apache.hadoop.conf.Configurablepublic int getPartition(org.apache.hadoop.io.BinaryComparable key,
V value,
int numPartitions)
BinaryComparable.getBytes() to partition.getPartition in class Partitioner<org.apache.hadoop.io.BinaryComparable,V>key - the key to be partioned.value - the entry value.numPartitions - the total number of partitions.key.Copyright © 2022 Apache Software Foundation. All rights reserved.