Class CellComparatorImpl

java.lang.Object
org.apache.hadoop.hbase.CellComparatorImpl
All Implemented Interfaces:
Serializable, Comparator<Cell>, CellComparator
Direct Known Subclasses:
InnerStoreCellComparator, MetaCellComparator

@Private @Evolving public class CellComparatorImpl extends Object implements CellComparator
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 Details

  • Constructor Details

  • Method Details

    • compare

      public final int compare(Cell a, Cell b)
      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 interface CellComparator
      Specified by:
      compare in interface Comparator<Cell>
      Parameters:
      a - the left hand side cell
      b - 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

      public int compare(Cell l, Cell r, boolean ignoreSequenceid)
      Description copied from interface: CellComparator
      Compare cells.
      Specified by:
      compare in interface CellComparator
      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

      private int compareKeyValues(KeyValue left, KeyValue right)
    • compareBBKV

    • compareKVVsBBKV

      private int compareKVVsBBKV(KeyValue left, ByteBufferKeyValue right)
    • compareColumns

      public final int compareColumns(Cell left, Cell right)
      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

      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.
    • compareQualifiers

      private final int compareQualifiers(Cell left, int leftQualLen, Cell right, int rightQualLen)
    • compareFamilies

      public final int compareFamilies(Cell left, Cell right)
      Compare the families of left and right cell
      Specified by:
      compareFamilies in interface CellComparator
      Parameters:
      left - the left hand side cell
      right - 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

      static int compareQualifiers(KeyValue left, KeyValue right)
    • compareQualifiers

      static int compareQualifiers(KeyValue left, ByteBufferKeyValue right)
    • compareQualifiers

      static int compareQualifiers(ByteBufferKeyValue left, KeyValue right)
    • compareQualifiers

    • compareQualifiers

      public final int compareQualifiers(Cell left, Cell right)
      Compare the qualifiers part of the left and right cells.
      Specified by:
      compareQualifiers in interface CellComparator
      Parameters:
      left - the left hand side cell
      right - the right hand side cell
      Returns:
      0 if both cells are equal, 1 if left cell is bigger than right, -1 otherwise
    • compareRows

      public int compareRows(Cell left, Cell right)
      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 interface CellComparator
      Parameters:
      left - the left hand side cell
      right - the right hand side cell
      Returns:
      0 if both cells are equal, 1 if left cell is bigger than right, -1 otherwise
    • compareRows

      static int compareRows(Cell left, int leftRowLength, Cell right, int rightRowLength)
    • compareRows

      public 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. 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 interface CellComparator
      Parameters:
      left - the cell
      right - the byte[] representing the row to be compared with
      roffset - 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

      public final int compareWithoutRow(Cell left, Cell right)
      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 interface CellComparator
      Parameters:
      left - the left hand side cell
      right - 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

      public int compareTimestamps(Cell left, Cell right)
      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 interface CellComparator
      Parameters:
      left - the left hand side cell
      right - 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

      public int compareTimestamps(long ltimestamp, long rtimestamp)
      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 interface CellComparator
      Parameters:
      ltimestamp - the left cell's timestamp
      rtimestamp - 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, the ByteBufferKeyValue. 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 interface CellComparator
    • getCellComparator

      public static CellComparator getCellComparator(TableName tableName)
      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

      public static CellComparator getCellComparator(byte[] tableName)
      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.