Package org.apache.hadoop.hbase
Class PrivateCellUtil
java.lang.Object
org.apache.hadoop.hbase.PrivateCellUtil
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static class
These cells are used in reseeks/seeks to improve the read performance.private static class
These cells are used in reseeks/seeks to improve the read performance.private static class
private static class
private static class
private static class
private static class
private static class
private static class
private static class
private static class
private static class
private static class
(package private) static class
(package private) static class
This can be used when a Cell has to change with addition/removal of one or more tags.(package private) static class
(package private) static class
-
Constructor Summary
ModifierConstructorDescriptionprivate
Private constructor to keep this class from being instantiated. -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
static final int
compare
(CellComparator comparator, Cell left, byte[] key, int offset, int length) Used when a cell needs to be compared with a key byte[] such as cases of finding the index from the index block, bloom keys from the bloom blocks This byte[] is expected to be serialized in the KeyValue serialization format If the KeyValue (Cell's) serialization format changes this method cannot be used.static int
compareFamily
(Cell cell, ByteArrayComparable comparator) Compare cell's column family against given comparatorstatic final int
compareKeyBasedOnColHint
(CellComparator comparator, Cell nextIndexedCell, Cell currentCell, int foff, int flen, byte[] colHint, int coff, int clen, long ts, byte type) Used to compare two cells based on the column hint provided.static final int
compareKeyIgnoresMvcc
(CellComparator comparator, Cell left, Cell right) Compares only the key portion of a cell.static int
compareQualifier
(Cell cell, ByteArrayComparable comparator) Compare cell's qualifier against given comparatorstatic int
compareRow
(Cell cell, ByteArrayComparable comparator) Compare cell's row against given comparatorstatic int
compareValue
(Cell cell, ByteArrayComparable comparator) Compare cell's value against given comparator(package private) static final int
compareWithoutRow
(CellComparator comparator, Cell left, byte[] right, int roffset, int rlength, short rowlength) Compare columnFamily, qualifier, timestamp, and key type (everything except the row).static void
compressFamily
(OutputStream out, Cell cell, Dictionary dict) static void
compressQualifier
(OutputStream out, Cell cell, Dictionary dict) static void
compressRow
(OutputStream out, Cell cell, Dictionary dict) static void
compressTags
(OutputStream out, Cell cell, TagCompressionContext tagCompressionContext) Compresses the tags to the given outputstream using the TagcompressionContextstatic int
copyTagsTo
(Cell cell, byte[] destination, int destinationOffset) Copies the tags info into the tag portion of the cellstatic int
copyTagsTo
(Cell cell, ByteBuffer destination, int destinationOffset) Copies the tags info into the tag portion of the cellstatic Cell
createCell
(Cell cell, byte[] tags) Returns A new cell which is having the extra tags also added to it.static Cell
createCell
(Cell cell, byte[] value, byte[] tags) static Cell
createCell
(Cell cell, List<Tag> tags) Returns A new cell which is having the extra tags also added to it.static Cell
createFirstDeleteFamilyCellOnRow
(byte[] row, byte[] fam) Create a Delete Family Cell for the specified row and family that would be smaller than all other possible Delete Family KeyValues that have the same row and family.static Cell
createFirstOnNextRow
(Cell cell) static Cell
createFirstOnRow
(byte[] row) static Cell
createFirstOnRow
(byte[] row, byte[] family, byte[] col) static Cell
createFirstOnRow
(byte[] row, int roffset, short rlength) static Cell
createFirstOnRow
(byte[] row, int roffset, short rlength, byte[] family, int foffset, byte flength, byte[] col, int coffset, int clength) static Cell
createFirstOnRow
(Cell cell) Create a Cell that is smaller than all other possible Cells for the given Cell's row.static Cell
createFirstOnRowCol
(Cell cell) static Cell
createFirstOnRowCol
(Cell cell, byte[] qArray, int qoffest, int qlength) Create a Cell that is smaller than all other possible Cells for the given Cell's rk:cf and passed qualifier.static Cell
createFirstOnRowColTS
(Cell cell, long ts) Creates the first cell with the row/family/qualifier of this cell and the given timestamp.static Cell
createFirstOnRowFamily
(Cell cell, byte[] fArray, int foff, int flen) static Cell
createLastOnRow
(byte[] row) static Cell
createLastOnRow
(Cell cell) Create a Cell that is larger than all other possible Cells for the given Cell's row.static Cell
createLastOnRowCol
(Cell cell) Create a Cell that is larger than all other possible Cells for the given Cell's rk:cf:q.static Cell
createNextOnRowCol
(Cell cell) Return a new cell is located following input cell.(package private) static Cell
createNextOnRowCol
(Cell cell, long ts, byte type) static Cell
Deep clones the given cell if the cell supports deep cloningstatic boolean
equalsIgnoreMvccVersion
(Cell a, Cell b) special case for Cell.equalsstatic int
Estimate based on keyvalue's serialization format in the RPC layer.static int
Calculates the serialized key size.static ByteRange
fillFamilyRange
(Cell cell, ByteRange range) static ByteRange
fillQualifierRange
(Cell cell, ByteRange range) static ByteRange
fillRowRange
(Cell cell, ByteRange range) ByteRangestatic ByteRange
fillTagRange
(Cell cell, ByteRange range) static ByteRange
fillValueRange
(Cell cell, ByteRange range) static int
findCommonPrefixInFlatKey
(Cell c1, Cell c2, boolean bypassFamilyCheck, boolean withTsType) Find length of common prefix in keys of the cells, considering key as byte[] if serialized inKeyValue
.static byte[]
This method exists just to encapsulate how we serialize keys.static byte
getQualifierByte
(Cell cell, int index) static int
getRowAsInt
(Cell cell) Converts the rowkey bytes of the given cell into an int valuestatic byte
getRowByte
(Cell cell, int index) miscRetrieve Cell's first tag, matching the passed in typeReturn tags in the given Cell as a Liststatic BigDecimal
getValueAsBigDecimal
(Cell cell) Converts the value bytes of the given cell into a BigDecimalstatic double
getValueAsDouble
(Cell cell) Converts the value bytes of the given cell into a double valuestatic int
getValueAsInt
(Cell cell) Converts the value bytes of the given cell into a int valuestatic long
getValueAsLong
(Cell cell) Converts the value bytes of the given cell into a long valuestatic ByteBuffer
static boolean
isDelete
(byte type) Return true if a delete type, aKeyValue.Type.Delete
or a {KeyValue.Type#DeleteFamily} or aKeyValue.Type.DeleteColumn
KeyValue type.static boolean
isDeleteColumnOrFamily
(Cell cell) Returns True if this cell is a delete family or column type.static boolean
isDeleteColumns
(Cell cell) static boolean
isDeleteColumnVersion
(Cell cell) static boolean
isDeleteFamily
(Cell cell) static boolean
isDeleteFamilyVersion
(Cell cell) static boolean
isDeleteType
(Cell cell) Returns True if this cell is aKeyValue.Type.Delete
type.static boolean
matchingColumn
(Cell left, byte[] fam, int foffset, int flength, byte[] qual, int qoffset, int qlength) static boolean
matchingFamily
(Cell left, byte[] buf, int offset, int length) static boolean
matchingQualifier
(Cell left, byte[] buf, int offset, int length) Finds if the qualifier part of the cell and the KV serialized byte[] are equalstatic boolean
matchingRows
(Cell left, byte[] buf, int offset, int length) static boolean
matchingTags
(Cell left, Cell right, int llength, int rlength) static boolean
matchingType
(Cell a, Cell b) static boolean
matchingValue
(Cell left, Cell right, int lvlength, int rvlength) static boolean
overlappingKeys
(byte[] start1, byte[] end1, byte[] start2, byte[] end2) Returns true if the first range start1...end1 overlaps with the second range start2...end2, assuming the byte arrays represent row keysstatic boolean
qualifierStartsWith
(Cell left, byte[] startsWith) Finds if the start of the qualifier part of the Cell matchesbuf
static void
setSequenceId
(Cell cell, long seqId) Sets the given seqId to the cell.static void
setTimestamp
(Cell cell, byte[] ts) Sets the given timestamp to the cell.static void
setTimestamp
(Cell cell, long ts) Sets the given timestamp to the cell.tagsIterator
(ByteBuffer tags, int offset, int length) tagsIterator
(Cell cell) Utility method to iterate through the tags in the given cell.static Cell.Type
toType
(byte type) static KeyValue.Type
toTypeByte
(Cell.Type type) static boolean
updateLatestStamp
(Cell cell, byte[] ts) Sets the given timestamp to the cell iff current timestamp isHConstants.LATEST_TIMESTAMP
.static boolean
updateLatestStamp
(Cell cell, long ts) Sets the given timestamp to the cell iff current timestamp isHConstants.LATEST_TIMESTAMP
.static int
writeCell
(Cell cell, OutputStream out, boolean withTags) Writes the cell to the given OutputStreamstatic void
writeCellToBuffer
(Cell cell, ByteBuffer buf, int offset) Writes a cell to the buffer at the given offsetstatic void
writeFamily
(OutputStream out, Cell cell, byte flength) Writes the family from the given cell to the output streamstatic void
writeFlatKey
(Cell cell, DataOutput out) Writes the Cell's key part as it would have serialized in a KeyValue.static int
writeFlatKey
(Cell cell, OutputStream out) static void
writeQualifier
(OutputStream out, Cell cell, int qlength) Writes the qualifier from the given cell to the output streamstatic void
writeQualifierSkippingBytes
(DataOutputStream out, Cell cell, int qlength, int commonPrefix) Writes the qualifier from the given cell to the output stream excluding the common prefixstatic void
writeRow
(OutputStream out, Cell cell, short rlength) Writes the row from the given cell to the output streamstatic void
writeRowKeyExcludingCommon
(Cell cell, short rLen, int commonPrefix, DataOutputStream out) Write rowkey excluding the common part.static void
writeRowSkippingBytes
(DataOutputStream out, Cell cell, short rlength, int commonPrefix) Writes the row from the given cell to the output stream excluding the common prefixstatic void
writeTags
(OutputStream out, Cell cell, int tagsLength) Writes the tag from the given cell to the output streamstatic void
writeValue
(OutputStream out, Cell cell, int vlength) Writes the value from the given cell to the output stream
-
Constructor Details
-
PrivateCellUtil
private PrivateCellUtil()Private constructor to keep this class from being instantiated.
-
-
Method Details
-
fillRowRange
ByteRange -
fillFamilyRange
-
fillQualifierRange
-
fillValueRange
-
fillTagRange
-
getRowByte
misc -
getQualifierByte
-
getValueBufferShallowCopy
-
createCell
Returns A new cell which is having the extra tags also added to it. -
createCell
Returns A new cell which is having the extra tags also added to it. -
createCell
-
matchingRows
-
matchingFamily
-
matchingQualifier
Finds if the qualifier part of the cell and the KV serialized byte[] are equal- Parameters:
left
- the cell with which we need to match the qualifierbuf
- the serialized keyvalue format byte[]offset
- the offset of the qualifier in the byte[]length
- the length of the qualifier in the byte[]- Returns:
- true if the qualifier matches, false otherwise
-
qualifierStartsWith
Finds if the start of the qualifier part of the Cell matchesbuf
- Parameters:
left
- the cell with which we need to match the qualifierstartsWith
- the serialized keyvalue format byte[]- Returns:
- true if the qualifier have same staring characters, false otherwise
-
matchingColumn
public static boolean matchingColumn(Cell left, byte[] fam, int foffset, int flength, byte[] qual, int qoffset, int qlength) -
matchingValue
-
matchingType
-
matchingTags
-
isDelete
Return true if a delete type, aKeyValue.Type.Delete
or a {KeyValue.Type#DeleteFamily} or aKeyValue.Type.DeleteColumn
KeyValue type. -
isDeleteType
Returns True if this cell is aKeyValue.Type.Delete
type. -
isDeleteFamily
-
isDeleteFamilyVersion
-
isDeleteColumns
-
isDeleteColumnVersion
-
isDeleteColumnOrFamily
Returns True if this cell is a delete family or column type. -
cloneTags
-
copyTagsTo
Copies the tags info into the tag portion of the cell -
copyTagsTo
Copies the tags info into the tag portion of the cell -
getTags
Return tags in the given Cell as a List- Parameters:
cell
- The Cell- Returns:
- Tags in the given Cell as a List
-
getTag
Retrieve Cell's first tag, matching the passed in type- Parameters:
cell
- The Celltype
- Type of the Tag to retrieve- Returns:
- Optional, empty if there is no tag of the passed in tag type
-
tagsIterator
Utility method to iterate through the tags in the given cell.- Parameters:
cell
- The Cell over which tags iterator is needed.- Returns:
- iterator for the tags
-
tagsIterator
-
overlappingKeys
Returns true if the first range start1...end1 overlaps with the second range start2...end2, assuming the byte arrays represent row keys -
writeRowKeyExcludingCommon
public static void writeRowKeyExcludingCommon(Cell cell, short rLen, int commonPrefix, DataOutputStream out) throws IOException Write rowkey excluding the common part.- Throws:
IOException
-
writeRowSkippingBytes
public static void writeRowSkippingBytes(DataOutputStream out, Cell cell, short rlength, int commonPrefix) throws IOException Writes the row from the given cell to the output stream excluding the common prefix- Parameters:
out
- The dataoutputstream to which the data has to be writtencell
- The cell whose contents has to be writtenrlength
- the row length- Throws:
IOException
-
findCommonPrefixInFlatKey
public static int findCommonPrefixInFlatKey(Cell c1, Cell c2, boolean bypassFamilyCheck, boolean withTsType) Find length of common prefix in keys of the cells, considering key as byte[] if serialized inKeyValue
. The key format is <2 bytes rk len><rk><1 byte cf len><cf><qualifier><8 bytes timestamp><1 byte type>- Parameters:
c1
- the cellc2
- the cellbypassFamilyCheck
- when true assume the family bytes same in both cells. Pass it as true when dealing with Cells in same CF so as to avoid some checkswithTsType
- when true check timestamp and type bytes also.- Returns:
- length of common prefix
-
compareKeyBasedOnColHint
public static final int compareKeyBasedOnColHint(CellComparator comparator, Cell nextIndexedCell, Cell currentCell, int foff, int flen, byte[] colHint, int coff, int clen, long ts, byte type) Used to compare two cells based on the column hint provided. This is specifically used when we need to optimize the seeks based on the next indexed key. This is an advanced usage API specifically needed for some optimizations.- Parameters:
nextIndexedCell
- the next indexed cellcurrentCell
- the cell to be comparedfoff
- the family offset of the currentCellflen
- the family length of the currentCellcolHint
- the column hint provided - could be nullcoff
- the offset of the column hint if provided, if not offset of the currentCell's qualifierclen
- the length of the column hint if provided, if not length of the currentCell's qualifierts
- the timestamp to be seekedtype
- the type to be seeked- Returns:
- an int based on the given column hint TODO : To be moved out of here because this is a special API used in scan optimization.
-
compareKeyIgnoresMvcc
Compares only the key portion of a cell. It does not include the sequence id/mvcc of the cell- Returns:
- an int greater than 0 if left > than right lesser than 0 if left < than right equal to 0 if left is equal to right
-
compareRow
Compare cell's row against given comparator- Parameters:
cell
- the cell to use for comparisoncomparator
- theCellComparator
to use for comparison- Returns:
- result comparing cell's row
-
compareFamily
Compare cell's column family against given comparator- Parameters:
cell
- the cell to use for comparisoncomparator
- theCellComparator
to use for comparison- Returns:
- result comparing cell's column family
-
compareQualifier
Compare cell's qualifier against given comparator- Parameters:
cell
- the cell to use for comparisoncomparator
- theCellComparator
to use for comparison- Returns:
- result comparing cell's qualifier
-
toType
-
toTypeByte
-
compareValue
Compare cell's value against given comparator- Parameters:
cell
- the cell to use for comparisoncomparator
- theCellComparator
to use for comparison- Returns:
- result comparing cell's value
-
writeFlatKey
Writes the Cell's key part as it would have serialized in a KeyValue. The format is <2 bytes rk len><rk><1 byte cf len><cf><qualifier><8 bytes timestamp><1 byte type>- Throws:
IOException
-
deepClone
Deep clones the given cell if the cell supports deep cloning- Parameters:
cell
- the cell to be cloned- Returns:
- the cloned cell
- Throws:
CloneNotSupportedException
-
writeCell
Writes the cell to the given OutputStream- Parameters:
cell
- the cell to be writtenout
- the outputstreamwithTags
- if tags are to be written or not- Returns:
- the total bytes written
- Throws:
IOException
-
writeCellToBuffer
Writes a cell to the buffer at the given offset- Parameters:
cell
- the cell to be writtenbuf
- the buffer to which the cell has to be wrritenoffset
- the offset at which the cell should be written
-
writeFlatKey
- Throws:
IOException
-
setSequenceId
Sets the given seqId to the cell. Marked as audience Private as of 1.2.0. Setting a Cell sequenceid is an internal implementation detail not for general public use.- Throws:
IOException
- when the passed cell is not of typeExtendedCell
-
setTimestamp
Sets the given timestamp to the cell.- Throws:
IOException
- when the passed cell is not of typeExtendedCell
-
setTimestamp
Sets the given timestamp to the cell.- Throws:
IOException
- when the passed cell is not of typeExtendedCell
-
updateLatestStamp
Sets the given timestamp to the cell iff current timestamp isHConstants.LATEST_TIMESTAMP
.- Returns:
- True if cell timestamp is modified.
- Throws:
IOException
- when the passed cell is not of typeExtendedCell
-
updateLatestStamp
Sets the given timestamp to the cell iff current timestamp isHConstants.LATEST_TIMESTAMP
.- Returns:
- True if cell timestamp is modified.
- Throws:
IOException
- when the passed cell is not of typeExtendedCell
-
writeRow
Writes the row from the given cell to the output stream- Parameters:
out
- The outputstream to which the data has to be writtencell
- The cell whose contents has to be writtenrlength
- the row length- Throws:
IOException
-
writeFamily
Writes the family from the given cell to the output stream- Parameters:
out
- The outputstream to which the data has to be writtencell
- The cell whose contents has to be writtenflength
- the family length- Throws:
IOException
-
writeQualifier
Writes the qualifier from the given cell to the output stream- Parameters:
out
- The outputstream to which the data has to be writtencell
- The cell whose contents has to be writtenqlength
- the qualifier length- Throws:
IOException
-
writeQualifierSkippingBytes
public static void writeQualifierSkippingBytes(DataOutputStream out, Cell cell, int qlength, int commonPrefix) throws IOException Writes the qualifier from the given cell to the output stream excluding the common prefix- Parameters:
out
- The dataoutputstream to which the data has to be writtencell
- The cell whose contents has to be writtenqlength
- the qualifier length- Throws:
IOException
-
writeValue
Writes the value from the given cell to the output stream- Parameters:
out
- The outputstream to which the data has to be writtencell
- The cell whose contents has to be writtenvlength
- the value length- Throws:
IOException
-
writeTags
Writes the tag from the given cell to the output stream- Parameters:
out
- The outputstream to which the data has to be writtencell
- The cell whose contents has to be writtentagsLength
- the tag length- Throws:
IOException
-
equalsIgnoreMvccVersion
special case for Cell.equals -
getRowAsInt
Converts the rowkey bytes of the given cell into an int value- Returns:
- rowkey as int
-
getValueAsLong
Converts the value bytes of the given cell into a long value- Returns:
- value as long
-
getValueAsInt
Converts the value bytes of the given cell into a int value- Returns:
- value as int
-
getValueAsDouble
Converts the value bytes of the given cell into a double value- Returns:
- value as double
-
getValueAsBigDecimal
Converts the value bytes of the given cell into a BigDecimal- Returns:
- value as BigDecimal
-
compressTags
public static void compressTags(OutputStream out, Cell cell, TagCompressionContext tagCompressionContext) throws IOException Compresses the tags to the given outputstream using the TagcompressionContext- Parameters:
out
- the outputstream to which the compression should happencell
- the cell which has tagstagCompressionContext
- the TagCompressionContext- Throws:
IOException
- can throw IOException if the compression encounters issue
-
compressRow
- Throws:
IOException
-
compressFamily
- Throws:
IOException
-
compressQualifier
public static void compressQualifier(OutputStream out, Cell cell, Dictionary dict) throws IOException - Throws:
IOException
-
compare
public static final int compare(CellComparator comparator, Cell left, byte[] key, int offset, int length) Used when a cell needs to be compared with a key byte[] such as cases of finding the index from the index block, bloom keys from the bloom blocks This byte[] is expected to be serialized in the KeyValue serialization format If the KeyValue (Cell's) serialization format changes this method cannot be used.- Parameters:
comparator
- theCellComparator
to use for comparisonleft
- the cell to be comparedkey
- the serialized key part of a KeyValueoffset
- the offset in the key byte[]length
- the length of the key byte[]- Returns:
- an int greater than 0 if left is greater than right lesser than 0 if left is lesser than right equal to 0 if left is equal to right
-
compareWithoutRow
static final int compareWithoutRow(CellComparator comparator, Cell left, byte[] right, int roffset, int rlength, short rowlength) Compare columnFamily, qualifier, timestamp, and key type (everything except the row). This method is used both in the normal comparator and the "same-prefix" comparator. Note that we are assuming that row portions of both KVs have already been parsed and found identical, and we don't validate that assumption here.- Parameters:
comparator
- theCellComparator
to use for comparisonleft
- the cell to be comparedright
- the serialized key part of a key-valueroffset
- the offset in the key byte[]rlength
- the length of the key byte[]rowlength
- the row length- Returns:
- greater than 0 if left cell is bigger, less than 0 if right cell is bigger, 0 if both cells are equal
-
createNextOnRowCol
Return a new cell is located following input cell. If both of type and timestamp are minimum, the input cell will be returned directly. -
createNextOnRowCol
-
estimatedSerializedSizeOf
Estimate based on keyvalue's serialization format in the RPC layer. Note that there is an extra SIZEOF_INT added to the size here that indicates the actual length of the cell for cases where cell's are serialized in a contiguous format (For eg in RPCs).- Returns:
- Estimate of the
cell
size in bytes plus an extra SIZEOF_INT indicating the actual cell length.
-
estimatedSerializedSizeOfKey
Calculates the serialized key size. We always serialize in the KeyValue's serialization format.- Parameters:
cell
- the cell for which the key size has to be calculated.- Returns:
- the key size
-
getCellKeySerializedAsKeyValueKey
This method exists just to encapsulate how we serialize keys. To be replaced by a factory that we query to figure what the Cell implementation is and then, what serialization engine to use and further, how to serialize the key for inclusion in hfile index. TODO.- Returns:
- The key portion of the Cell serialized in the old-school KeyValue way or null if passed
a null
cell
-
createFirstOnRow
Create a Cell that is smaller than all other possible Cells for the given Cell's row.- Returns:
- First possible Cell on passed Cell's row.
-
createFirstOnRow
-
createFirstOnRow
-
createFirstOnRow
public static Cell createFirstOnRow(byte[] row, int roffset, short rlength, byte[] family, int foffset, byte flength, byte[] col, int coffset, int clength) -
createFirstOnRow
-
createFirstOnRowFamily
-
createFirstOnRowCol
-
createFirstOnNextRow
-
createFirstOnRowCol
Create a Cell that is smaller than all other possible Cells for the given Cell's rk:cf and passed qualifier.- Returns:
- Last possible Cell on passed Cell's rk:cf and passed qualifier.
-
createFirstOnRowColTS
Creates the first cell with the row/family/qualifier of this cell and the given timestamp. Uses the "maximum" type that guarantees that the new cell is the lowest possible for this combination of row, family, qualifier, and timestamp. This cell's own timestamp is ignored.- Parameters:
cell
- - cell
-
createLastOnRow
Create a Cell that is larger than all other possible Cells for the given Cell's row.- Returns:
- Last possible Cell on passed Cell's row.
-
createLastOnRow
-
createLastOnRowCol
Create a Cell that is larger than all other possible Cells for the given Cell's rk:cf:q. Used in creating "fake keys" for the multi-column Bloom filter optimization to skip the row/column we already know is not in the file.- Returns:
- Last possible Cell on passed Cell's rk:cf:q.
-
createFirstDeleteFamilyCellOnRow
Create a Delete Family Cell for the specified row and family that would be smaller than all other possible Delete Family KeyValues that have the same row and family. Used for seeking.- Parameters:
row
- - row key (arbitrary byte array)fam
- - family name- Returns:
- First Delete Family possible key on passed
row
.
-