Package org.apache.hadoop.hbase
Class CellComparatorImpl
java.lang.Object
org.apache.hadoop.hbase.CellComparatorImpl
- All Implemented Interfaces:
Serializable
,Comparator<Cell>
,CellComparator
- Direct Known Subclasses:
InnerStoreCellComparator
,MetaCellComparator
Compare two HBase cells. Do not use this method comparing
-ROOT-
or
hbase:meta
cells. Cells from these tables need a specialized comparator, one that
takes account of the special formatting of the row where we have commas to delimit table from
regionname, from row. See KeyValue for how it has a special comparator to do hbase:meta cells and
yet another for -ROOT-.
While using this comparator for {compareRows(Cell, Cell)
et al, the hbase:meta cells
format should be taken into consideration, for which the instance of this comparator should be
used. In all other cases the static APIs in this comparator would be enough
HOT methods. We spend a good portion of CPU comparing. Anything that makes the compare faster will likely manifest at the macro level.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final CellComparatorImpl
Comparator for plain key/values; i.e.private static final long
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal int
Lexographically compares two cells.int
Compare cells.private int
compareBBKV
(ByteBufferKeyValue left, ByteBufferKeyValue right) private int
compareColumns
(Cell left, int leftFamLen, int leftQualLen, Cell right, int rightFamLen, int rightQualLen) final int
compareColumns
(Cell left, Cell right) Compares the family and qualifier part of the cellprotected int
compareFamilies
(ByteBufferKeyValue left, int leftFamilyPosition, int leftFamilyLength, ByteBufferKeyValue right, int rightFamilyPosition, int rightFamilyLength) This method will be overridden when we compare cells inner store to bypass family comparing.protected int
compareFamilies
(Cell left, int leftFamLen, Cell right, int rightFamLen) This method will be overridden when we compare cells inner store to bypass family comparing.final int
compareFamilies
(Cell left, Cell right) Compare the families of left and right cellprotected int
compareFamilies
(KeyValue left, int leftFamilyPosition, int leftFamilyLength, ByteBufferKeyValue right, int rightFamilyPosition, int rightFamilyLength) This method will be overridden when we compare cells inner store to bypass family comparing.protected int
compareFamilies
(KeyValue left, int leftFamilyPosition, int leftFamilyLength, KeyValue right, int rightFamilyPosition, int rightFamilyLength) This method will be overridden when we compare cells inner store to bypass family comparing.private int
compareKeyValues
(KeyValue left, KeyValue right) private int
compareKVVsBBKV
(KeyValue left, ByteBufferKeyValue right) (package private) static int
compareQualifiers
(ByteBufferKeyValue left, ByteBufferKeyValue right) (package private) static int
compareQualifiers
(ByteBufferKeyValue left, KeyValue right) private final int
compareQualifiers
(Cell left, int leftQualLen, Cell right, int rightQualLen) final int
compareQualifiers
(Cell left, Cell right) Compare the qualifiers part of the left and right cells.(package private) static int
compareQualifiers
(KeyValue left, ByteBufferKeyValue right) (package private) static int
compareQualifiers
(KeyValue left, KeyValue right) int
compareRows
(Cell left, byte[] right, int roffset, int rlength) Compares the row part of the cell with a simple plain byte[] like the stopRow in Scan.(package private) static int
compareRows
(Cell left, int leftRowLength, Cell right, int rightRowLength) int
compareRows
(Cell left, Cell right) Compares the rows of the left and right cell.int
compareTimestamps
(long ltimestamp, long rtimestamp) Compares cell's timestamps in DESCENDING order.int
compareTimestamps
(Cell left, Cell right) Compares cell's timestamps in DESCENDING order.final int
compareWithoutRow
(Cell left, Cell right) Lexicographically compares the two cells excluding the row part.static CellComparator
getCellComparator
(byte[] tableName) Utility method that makes a guess at comparator to use based off passed tableName.static CellComparator
getCellComparator
(TableName tableName) Utility method that makes a guess at comparator to use based off passed tableName.Return a dumbed-down, fast comparator for hbase2 base-type, theByteBufferKeyValue
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.hadoop.hbase.CellComparator
compareRows, compareRows
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
serialVersionUID
- See Also:
-
COMPARATOR
Comparator for plain key/values; i.e. non-catalog table key/values. Works on Key portion of KeyValue only.
-
-
Constructor Details
-
CellComparatorImpl
public CellComparatorImpl()
-
-
Method Details
-
compare
Description copied from interface:CellComparator
Lexographically compares two cells. The key part of the cell is taken for comparison which includes row, family, qualifier, timestamp and type- Specified by:
compare
in interfaceCellComparator
- Specified by:
compare
in interfaceComparator<Cell>
- Parameters:
a
- the left hand side cellb
- the right hand side cell- Returns:
- greater than 0 if leftCell is bigger, less than 0 if rightCell is bigger, 0 if both cells are equal
-
compare
Description copied from interface:CellComparator
Compare cells.- Specified by:
compare
in interfaceCellComparator
ignoreSequenceid
- True if we are to compare the key portion only and ignore the sequenceid. Set to false to compare key and consider sequenceid.- Returns:
- 0 if equal, -1 if a < b, and +1 if a > b.
-
compareKeyValues
-
compareBBKV
-
compareKVVsBBKV
-
compareColumns
Compares the family and qualifier part of the cell- Returns:
- 0 if both cells are equal, 1 if left cell is bigger than right, -1 otherwise
-
compareColumns
private int compareColumns(Cell left, int leftFamLen, int leftQualLen, Cell right, int rightFamLen, int rightQualLen) -
compareFamilies
This method will be overridden when we compare cells inner store to bypass family comparing. -
compareQualifiers
-
compareFamilies
Compare the families of left and right cell- Specified by:
compareFamilies
in interfaceCellComparator
- Parameters:
left
- the left hand side cellright
- the right hand side cell- Returns:
- 0 if both cells are equal, 1 if left cell is bigger than right, -1 otherwise
-
compareFamilies
protected int compareFamilies(KeyValue left, int leftFamilyPosition, int leftFamilyLength, KeyValue right, int rightFamilyPosition, int rightFamilyLength) This method will be overridden when we compare cells inner store to bypass family comparing. -
compareFamilies
protected int compareFamilies(ByteBufferKeyValue left, int leftFamilyPosition, int leftFamilyLength, ByteBufferKeyValue right, int rightFamilyPosition, int rightFamilyLength) This method will be overridden when we compare cells inner store to bypass family comparing. -
compareFamilies
protected int compareFamilies(KeyValue left, int leftFamilyPosition, int leftFamilyLength, ByteBufferKeyValue right, int rightFamilyPosition, int rightFamilyLength) This method will be overridden when we compare cells inner store to bypass family comparing. -
compareQualifiers
-
compareQualifiers
-
compareQualifiers
-
compareQualifiers
-
compareQualifiers
Compare the qualifiers part of the left and right cells.- Specified by:
compareQualifiers
in interfaceCellComparator
- Parameters:
left
- the left hand side cellright
- the right hand side cell- Returns:
- 0 if both cells are equal, 1 if left cell is bigger than right, -1 otherwise
-
compareRows
Compares the rows of the left and right cell. For the hbase:meta case this method is overridden such that it can handle hbase:meta cells. The caller should ensure using the appropriate comparator for hbase:meta.- Specified by:
compareRows
in interfaceCellComparator
- Parameters:
left
- the left hand side cellright
- the right hand side cell- Returns:
- 0 if both cells are equal, 1 if left cell is bigger than right, -1 otherwise
-
compareRows
-
compareRows
Compares the row part of the cell with a simple plain byte[] like the stopRow in Scan. This should be used with context where for hbase:meta cells the {MetaCellComparator.META_COMPARATOR
should be used the cell to be compared the kv serialized byte[] to be compared with the offset in the byte[] the length in the byte[]- Specified by:
compareRows
in interfaceCellComparator
- Parameters:
left
- the cellright
- the byte[] representing the row to be compared withroffset
- the offset of the byte[]rlength
- the length of the byte[]- Returns:
- 0 if both cell and the byte[] are equal, 1 if the cell is bigger than byte[], -1 otherwise
-
compareWithoutRow
Description copied from interface:CellComparator
Lexicographically compares the two cells excluding the row part. It compares family, qualifier, timestamp and the type- Specified by:
compareWithoutRow
in interfaceCellComparator
- Parameters:
left
- the left hand side cellright
- the right hand side cell- Returns:
- greater than 0 if leftCell is bigger, less than 0 if rightCell is bigger, 0 if both cells are equal
-
compareTimestamps
Description copied from interface:CellComparator
Compares cell's timestamps in DESCENDING order. The below older timestamps sorting ahead of newer timestamps looks wrong but it is intentional. This way, newer timestamps are first found when we iterate over a memstore and newer versions are the first we trip over when reading from a store file.- Specified by:
compareTimestamps
in interfaceCellComparator
- Parameters:
left
- the left hand side cellright
- the right hand side cell- Returns:
- 1 if left's timestamp < right's timestamp -1 if left's timestamp > right's timestamp 0 if both timestamps are equal
-
compareTimestamps
Description copied from interface:CellComparator
Compares cell's timestamps in DESCENDING order. The below older timestamps sorting ahead of newer timestamps looks wrong but it is intentional. This way, newer timestamps are first found when we iterate over a memstore and newer versions are the first we trip over when reading from a store file.- Specified by:
compareTimestamps
in interfaceCellComparator
- Parameters:
ltimestamp
- the left cell's timestamprtimestamp
- the right cell's timestamp- Returns:
- 1 if left's timestamp < right's timestamp -1 if left's timestamp > right's timestamp 0 if both timestamps are equal
-
getSimpleComparator
Description copied from interface:CellComparator
Return a dumbed-down, fast comparator for hbase2 base-type, theByteBufferKeyValue
. Create an instance when you make a new memstore, when you know only BBKVs will be passed. Do not pollute with types other than BBKV if can be helped; the Comparator will slow.- Specified by:
getSimpleComparator
in interfaceCellComparator
-
getCellComparator
Utility method that makes a guess at comparator to use based off passed tableName. Use in extreme when no comparator specified.- Returns:
- CellComparator to use going off the
tableName
passed.
-
getCellComparator
Utility method that makes a guess at comparator to use based off passed tableName. Use in extreme when no comparator specified.- Returns:
- CellComparator to use going off the
tableName
passed.
-