Interface CellComparator

All Superinterfaces:
Comparator<Cell>, Serializable
All Known Implementing Classes:
CellComparatorImpl, InnerStoreCellComparator, MetaCellComparator

@Public @Evolving public interface CellComparator extends Comparator<Cell>, Serializable
Comparator for comparing cells and has some specialized methods that allows comparing individual cell components like row, family, qualifier and timestamp
  • Method Details

    • getInstance

      A comparator for ordering cells in user-space tables. Useful when writing cells in sorted order as necessary for bulk import (i.e. via MapReduce).

      CAUTION: This comparator may provide inaccurate ordering for cells from system tables, and should not be relied upon in that case.

    • compare

      int compare(Cell leftCell, Cell rightCell)
      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 Comparator<Cell>
      Parameters:
      leftCell - the left hand side cell
      rightCell - 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

      int compare(Cell leftCell, Cell rightCell, boolean ignoreSequenceid)
      Compare cells.
      Parameters:
      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.
    • compareRows

      int compareRows(Cell leftCell, Cell rightCell)
      Lexographically compares the rows of two cells.
      Parameters:
      leftCell - the left hand side cell
      rightCell - 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
    • compareRows

      int compareRows(Cell cell, byte[] bytes, int offset, int length)
      Compares the row part of the cell with a simple plain byte[] like the stopRow in Scan.
      Parameters:
      cell - the cell
      bytes - the byte[] representing the row to be compared with
      offset - the offset of the byte[]
      length - the length of the byte[]
      Returns:
      greater than 0 if leftCell is bigger, less than 0 if rightCell is bigger, 0 if both cells are equal
    • compareRows

      default int compareRows(byte[] leftRow, byte[] rightRow)
      Compares two row bytes
      Parameters:
      leftRow - the byte array of the left row
      rightRow - the byte array of the right row
      Returns:
      greater than 0 if leftRow is bigger, less than 0 if rightRow is bigger, 0 if both rows are equal
    • compareRows

      default int compareRows(ByteBuffer row, Cell cell)
      Lexicographically compare two rows
      Parameters:
      row - ByteBuffer that wraps a row; will read from current position and will reading all remaining; will not disturb the ByteBuffer internal state.
      Returns:
      greater than 0 if leftCell is bigger, less than 0 if rightCell is bigger, 0 if both cells are equal
    • compareWithoutRow

      int compareWithoutRow(Cell leftCell, Cell rightCell)
      Lexicographically compares the two cells excluding the row part. It compares family, qualifier, timestamp and the type
      Parameters:
      leftCell - the left hand side cell
      rightCell - 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
    • compareFamilies

      int compareFamilies(Cell leftCell, Cell rightCell)
      Lexicographically compares the families of the two cells
      Parameters:
      leftCell - the left hand side cell
      rightCell - 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
    • compareQualifiers

      int compareQualifiers(Cell leftCell, Cell rightCell)
      Lexicographically compares the qualifiers of the two cells
      Parameters:
      leftCell - the left hand side cell
      rightCell - 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

      int compareTimestamps(Cell leftCell, Cell rightCell)
      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.
      Parameters:
      leftCell - the left hand side cell
      rightCell - 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

      int compareTimestamps(long leftCellts, long rightCellts)
      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.
      Parameters:
      leftCellts - the left cell's timestamp
      rightCellts - 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

      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.