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 BBKVComparator. Use it when mostly
ByteBufferKeyValues.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CellComparatorImplComparator for plain key/values; i.e.private static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal intLexographically compares two cells.intCompare cells.private intcompareBBKV(ByteBufferKeyValue left, ByteBufferKeyValue right) private intcompareColumns(Cell left, int leftFamLen, int leftQualLen, Cell right, int rightFamLen, int rightQualLen) final intcompareColumns(Cell left, Cell right) Compares the family and qualifier part of the cellprotected intcompareFamilies(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 intcompareFamilies(Cell left, int leftFamLen, Cell right, int rightFamLen) This method will be overridden when we compare cells inner store to bypass family comparing.final intcompareFamilies(Cell left, Cell right) Compare the families of left and right cellprotected intcompareFamilies(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 intcompareFamilies(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 intcompareKeyValues(KeyValue left, KeyValue right) private intcompareKVVsBBKV(KeyValue left, ByteBufferKeyValue right) (package private) static intcompareQualifiers(ByteBufferKeyValue left, ByteBufferKeyValue right) (package private) static intcompareQualifiers(ByteBufferKeyValue left, KeyValue right) private final intcompareQualifiers(Cell left, int leftQualLen, Cell right, int rightQualLen) final intcompareQualifiers(Cell left, Cell right) Compare the qualifiers part of the left and right cells.(package private) static intcompareQualifiers(KeyValue left, ByteBufferKeyValue right) (package private) static intcompareQualifiers(KeyValue left, KeyValue right) intcompareRows(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 intcompareRows(Cell left, int leftRowLength, Cell right, int rightRowLength) intcompareRows(Cell left, Cell right) Compares the rows of the left and right cell.intcompareTimestamps(long ltimestamp, long rtimestamp) Compares cell's timestamps in DESCENDING order.intcompareTimestamps(Cell left, Cell right) Compares cell's timestamps in DESCENDING order.final intcompareWithoutRow(Cell left, Cell right) Lexicographically compares the two cells excluding the row part.static CellComparatorgetCellComparator(byte[] tableName) Utility method that makes a guess at comparator to use based off passed tableName.static CellComparatorgetCellComparator(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, waitMethods inherited from interface org.apache.hadoop.hbase.CellComparator
compareRows, compareRowsMethods 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:CellComparatorLexographically compares two cells. The key part of the cell is taken for comparison which includes row, family, qualifier, timestamp and type- Specified by:
comparein interfaceCellComparator- Specified by:
comparein 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:CellComparatorCompare cells.- Specified by:
comparein interfaceCellComparatorignoreSequenceid- 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:
compareFamiliesin 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:
compareQualifiersin 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:
compareRowsin 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_COMPARATORshould 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:
compareRowsin 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:CellComparatorLexicographically compares the two cells excluding the row part. It compares family, qualifier, timestamp and the type- Specified by:
compareWithoutRowin 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:CellComparatorCompares 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:
compareTimestampsin 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:CellComparatorCompares 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:
compareTimestampsin 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:CellComparatorReturn 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:
getSimpleComparatorin 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
tableNamepassed.
-
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
tableNamepassed.
-