Class CellUtil

java.lang.Object
org.apache.hadoop.hbase.CellUtil

@Public public final class CellUtil extends Object
Utility methods helpful for slinging Cell instances. Some methods below are for internal use only and are marked InterfaceAudience.Private at the method level. Note that all such methods have been marked deprecated in HBase-2.0 which will be subsequently removed in HBase-3.0
  • Constructor Details

    • CellUtil

      private CellUtil()
      Private constructor to keep this class from being instantiated.
  • Method Details

    • cloneRow

      public static byte[] cloneRow(Cell cell)
      get individual arrays for tests
    • cloneFamily

      public static byte[] cloneFamily(Cell cell)
    • cloneQualifier

      public static byte[] cloneQualifier(Cell cell)
    • cloneValue

      public static byte[] cloneValue(Cell cell)
    • makeColumn

      public static byte[] makeColumn(byte[] family, byte[] qualifier)
      Makes a column in family:qualifier form from separate byte arrays.

      Not recommended for usage as this is old-style API.

      Returns:
      family:qualifier
    • parseColumn

      public static byte[][] parseColumn(byte[] c)
      Splits a column in family:qualifier form into separate byte arrays. An empty qualifier (ie, fam:) is parsed as { fam, EMPTY_BYTE_ARRAY } while no delimiter (ie, fam) is parsed as an array of one element, { fam }.

      Don't forget, HBase DOES support empty qualifiers. (see HBASE-9549)

      Not recommend to be used as this is old-style API.

      Parameters:
      c - The column.
      Returns:
      The parsed column.
    • copyRowTo

      public static int copyRowTo(Cell cell, byte[] destination, int destinationOffset)
      Copies the row to the given byte[]
      Parameters:
      cell - the cell whose row has to be copied
      destination - the destination byte[] to which the row has to be copied
      destinationOffset - the offset in the destination byte[]
      Returns:
      the offset of the byte[] after the copy has happened
    • copyRowTo

      public static int copyRowTo(Cell cell, ByteBuffer destination, int destinationOffset)
      Copies the row to the given bytebuffer
      Parameters:
      cell - cell the cell whose row has to be copied
      destination - the destination bytebuffer to which the row has to be copied
      destinationOffset - the offset in the destination byte[]
      Returns:
      the offset of the bytebuffer after the copy has happened
    • copyRow

      public static byte[] copyRow(Cell cell)
      Copies the row to a new byte[]
      Parameters:
      cell - the cell from which row has to copied
      Returns:
      the byte[] containing the row
    • copyFamilyTo

      public static int copyFamilyTo(Cell cell, byte[] destination, int destinationOffset)
      Copies the family to the given byte[]
      Parameters:
      cell - the cell whose family has to be copied
      destination - the destination byte[] to which the family has to be copied
      destinationOffset - the offset in the destination byte[]
      Returns:
      the offset of the byte[] after the copy has happened
    • copyFamilyTo

      public static int copyFamilyTo(Cell cell, ByteBuffer destination, int destinationOffset)
      Copies the family to the given bytebuffer
      Parameters:
      cell - the cell whose family has to be copied
      destination - the destination bytebuffer to which the family has to be copied
      destinationOffset - the offset in the destination bytebuffer
      Returns:
      the offset of the bytebuffer after the copy has happened
    • copyQualifierTo

      public static int copyQualifierTo(Cell cell, byte[] destination, int destinationOffset)
      Copies the qualifier to the given byte[]
      Parameters:
      cell - the cell whose qualifier has to be copied
      destination - the destination byte[] to which the qualifier has to be copied
      destinationOffset - the offset in the destination byte[]
      Returns:
      the offset of the byte[] after the copy has happened
    • copyQualifierTo

      public static int copyQualifierTo(Cell cell, ByteBuffer destination, int destinationOffset)
      Copies the qualifier to the given bytebuffer
      Parameters:
      cell - the cell whose qualifier has to be copied
      destination - the destination bytebuffer to which the qualifier has to be copied
      destinationOffset - the offset in the destination bytebuffer
      Returns:
      the offset of the bytebuffer after the copy has happened
    • copyValueTo

      public static int copyValueTo(Cell cell, byte[] destination, int destinationOffset)
      Copies the value to the given byte[]
      Parameters:
      cell - the cell whose value has to be copied
      destination - the destination byte[] to which the value has to be copied
      destinationOffset - the offset in the destination byte[]
      Returns:
      the offset of the byte[] after the copy has happened
    • copyValueTo

      public static int copyValueTo(Cell cell, ByteBuffer destination, int destinationOffset)
      Copies the value to the given bytebuffer
      Parameters:
      cell - the cell whose value has to be copied
      destination - the destination bytebuffer to which the value has to be copied
      destinationOffset - the offset in the destination bytebuffer
      Returns:
      the offset of the bytebuffer after the copy has happened
    • createCellScanner

      public static CellScanner createCellScanner(List<? extends CellScannable> cellScannerables)
      Returns CellScanner interface over cellIterables
    • createCellScanner

      public static CellScanner createCellScanner(Iterable<Cell> cellIterable)
      Returns CellScanner interface over cellIterable
    • createCellScanner

      public static CellScanner createCellScanner(Iterator<Cell> cells)
      Returns CellScanner interface over cellIterable or null if cells is null
    • createCellScanner

      public static CellScanner createCellScanner(Cell[] cellArray)
      Returns CellScanner interface over cellArray
    • createCellScanner

      public static CellScanner createCellScanner(NavigableMap<byte[],List<Cell>> map)
      Flatten the map of cells out under the CellScanner
      Parameters:
      map - Map of Cell Lists; for example, the map of families to Cells that is used inside Put, etc., keeping Cells organized by family.
      Returns:
      CellScanner interface over cellIterable
    • matchingRows

      public static boolean matchingRows(Cell left, byte[] buf)
    • matchingRow

      public static boolean matchingRow(Cell left, byte[] buf, int offset, int length)
    • matchingFamily

      public static boolean matchingFamily(Cell left, Cell right)
    • matchingFamily

      public static boolean matchingFamily(Cell left, byte lfamlength, Cell right, byte rfamlength)
    • matchingFamily

      public static boolean matchingFamily(Cell left, byte[] buf)
    • matchingQualifier

      public static boolean matchingQualifier(Cell left, Cell right)
    • matchingQualifier

      private static boolean matchingQualifier(Cell left, int lqlength, Cell right, int rqlength)
    • matchingQualifier

      public static boolean matchingQualifier(Cell left, byte[] buf)
      Finds if the qualifier part of the cell and the KV serialized byte[] are equal.
      Returns:
      true if the qualifier matches, false otherwise
    • matchingColumn

      public static boolean matchingColumn(Cell left, byte[] fam, byte[] qual)
    • matchingColumnFamilyAndQualifierPrefix

      public static boolean matchingColumnFamilyAndQualifierPrefix(Cell left, byte[] fam, byte[] qual)
      Returns True if matching column family and the qualifier starts with qual
    • matchingColumn

      public static boolean matchingColumn(Cell left, Cell right)
    • matchingColumn

      private static boolean matchingColumn(Cell left, byte lFamLen, int lQualLength, Cell right, byte rFamLen, int rQualLength)
    • matchingValue

      public static boolean matchingValue(Cell left, Cell right)
    • matchingValue

      public static boolean matchingValue(Cell left, Cell right, int lvlength, int rvlength)
    • matchingValue

      public static boolean matchingValue(Cell left, byte[] buf)
    • matchingTags

      @Deprecated public static boolean matchingTags(Cell left, Cell right)
      Deprecated.
      Since 3.0.0, will be removed in 4.0.0. Tags are now internal only, you should not try to check it through the Cell interface.
    • isDelete

      public static boolean isDelete(Cell cell)
      Return true if a delete type, a KeyValue.Type.Delete or a {KeyValue.Type#DeleteFamily} or a KeyValue.Type.DeleteColumn KeyValue type.
    • isPut

      public static boolean isPut(Cell cell)
      Returns True if this cell is a Put.
    • setTimestamp

      @LimitedPrivate("Coprocesssor") public static void setTimestamp(Cell cell, long ts) throws IOException
      Sets the given timestamp to the cell. Note that this method is a LimitedPrivate API and may change between minor releases.
      Throws:
      IOException - when the passed cell is not of type ExtendedCell
    • setTimestamp

      @LimitedPrivate("Coprocesssor") public static void setTimestamp(Cell cell, byte[] ts, int tsOffset) throws IOException
      Sets the given timestamp to the cell. Note that this method is a LimitedPrivate API and may change between minor releases.
      Throws:
      IOException - when the passed cell is not of type ExtendedCell
    • getCellKeyAsString

      public static String getCellKeyAsString(Cell cell)
      Returns The Key portion of the passed cell as a String.
    • getCellKeyAsString

      public static String getCellKeyAsString(Cell cell, Function<Cell,String> rowConverter)
      Return the Key portion of the passed cell as a String.
      Parameters:
      cell - the cell to convert
      rowConverter - used to convert the row of the cell to a string
      Returns:
      The Key portion of the passed cell as a String.
    • toString

      public static String toString(Cell cell, boolean verbose)
      Returns a string representation of the cell
    • equals

      public static boolean equals(Cell a, Cell b)
      equals
    • matchingTimestamp

      public static boolean matchingTimestamp(Cell a, Cell b)
    • matchingRows

      public static boolean matchingRows(Cell left, Cell right)
      Compares the row of two keyvalues for equality
    • matchingRows

      public static boolean matchingRows(Cell left, short lrowlength, Cell right, short rrowlength)
      Compares the row of two keyvalues for equality
    • matchingRowColumn

      public static boolean matchingRowColumn(Cell left, Cell right)
      Compares the row and column of two keyvalues for equality
    • matchingRowColumnBytes

      public static boolean matchingRowColumnBytes(Cell left, Cell right)
      Compares the row and column of two keyvalues for equality
    • compareQualifiers

      public static final int compareQualifiers(Cell left, byte[] right, int rOffset, int rLength)
      Compares the cell's qualifier with the given byte[]
      Parameters:
      left - the cell for which the qualifier has to be compared
      right - the byte[] having the qualifier
      rOffset - the offset of the qualifier
      rLength - the length of the qualifier
      Returns:
      greater than 0 if left cell's qualifier is bigger than byte[], lesser than 0 if left cell's qualifier is lesser than byte[] and 0 otherwise
    • compareFamilies

      public static final int compareFamilies(Cell left, byte[] right, int roffset, int rlength)
      Compares the cell's family with the given byte[]
      Parameters:
      left - the cell for which the family has to be compared
      right - the byte[] having the family
      roffset - the offset of the family
      rlength - the length of the family
      Returns:
      greater than 0 if left cell's family is bigger than byte[], lesser than 0 if left cell's family is lesser than byte[] and 0 otherwise
    • compareColumns

      public static final int compareColumns(Cell left, byte[] right, int rfoffset, int rflength, int rqoffset, int rqlength)
      Compares the cell's column (family and qualifier) with the given byte[]
      Parameters:
      left - the cell for which the column has to be compared
      right - the byte[] having the column
      rfoffset - the offset of the family
      rflength - the length of the family
      rqoffset - the offset of the qualifier
      rqlength - the length of the qualifier
      Returns:
      greater than 0 if left cell's column is bigger than byte[], lesser than 0 if left cell's column is lesser than byte[] and 0 otherwise
    • cloneIfNecessary

      public static void cloneIfNecessary(ArrayList<Cell> cells)
    • cloneIfNecessary

      public static Cell cloneIfNecessary(Cell cell)