Package org.apache.hadoop.hbase
Class PrivateCellUtil
java.lang.Object
org.apache.hadoop.hbase.PrivateCellUtil
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classThese cells are used in reseeks/seeks to improve the read performance.private static classThese cells are used in reseeks/seeks to improve the read performance.private static classprivate static classprivate static classprivate static classprivate static classprivate static classprivate static classprivate static classprivate static classprivate static classprivate static class(package private) static class(package private) static classThis 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
ConstructorsModifierConstructorDescriptionprivatePrivate constructor to keep this class from being instantiated. -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]static final intcompare(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 intcompareFamily(Cell cell, ByteArrayComparable comparator) Compare cell's column family against given comparatorstatic final intcompareKeyBasedOnColHint(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 intcompareKeyIgnoresMvcc(CellComparator comparator, Cell left, Cell right) Compares only the key portion of a cell.static intcompareQualifier(Cell cell, ByteArrayComparable comparator) Compare cell's qualifier against given comparatorstatic intcompareRow(Cell cell, ByteArrayComparable comparator) Compare cell's row against given comparatorstatic intcompareValue(Cell cell, ByteArrayComparable comparator) Compare cell's value against given comparator(package private) static final intcompareWithoutRow(CellComparator comparator, Cell left, byte[] right, int roffset, int rlength, short rowlength) Compare columnFamily, qualifier, timestamp, and key type (everything except the row).static voidcompressFamily(OutputStream out, Cell cell, Dictionary dict) static voidcompressQualifier(OutputStream out, Cell cell, Dictionary dict) static voidcompressRow(OutputStream out, Cell cell, Dictionary dict) static voidcompressTags(OutputStream out, Cell cell, TagCompressionContext tagCompressionContext) Compresses the tags to the given outputstream using the TagcompressionContextstatic intcopyTagsTo(Cell cell, byte[] destination, int destinationOffset) Copies the tags info into the tag portion of the cellstatic intcopyTagsTo(Cell cell, ByteBuffer destination, int destinationOffset) Copies the tags info into the tag portion of the cellstatic CellcreateCell(Cell cell, byte[] tags) Returns A new cell which is having the extra tags also added to it.static CellcreateCell(Cell cell, byte[] value, byte[] tags) static CellcreateCell(Cell cell, List<Tag> tags) Returns A new cell which is having the extra tags also added to it.static CellcreateFirstDeleteFamilyCellOnRow(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 CellcreateFirstOnNextRow(Cell cell) static CellcreateFirstOnRow(byte[] row) static CellcreateFirstOnRow(byte[] row, byte[] family, byte[] col) static CellcreateFirstOnRow(byte[] row, int roffset, short rlength) static CellcreateFirstOnRow(byte[] row, int roffset, short rlength, byte[] family, int foffset, byte flength, byte[] col, int coffset, int clength) static CellcreateFirstOnRow(Cell cell) Create a Cell that is smaller than all other possible Cells for the given Cell's row.static CellcreateFirstOnRowCol(Cell cell) static CellcreateFirstOnRowCol(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 CellcreateFirstOnRowColTS(Cell cell, long ts) Creates the first cell with the row/family/qualifier of this cell and the given timestamp.static CellcreateFirstOnRowFamily(Cell cell, byte[] fArray, int foff, int flen) static CellcreateLastOnRow(byte[] row) static CellcreateLastOnRow(Cell cell) Create a Cell that is larger than all other possible Cells for the given Cell's row.static CellcreateLastOnRowCol(Cell cell) Create a Cell that is larger than all other possible Cells for the given Cell's rk:cf:q.static CellcreateNextOnRowCol(Cell cell) Return a new cell is located following input cell.(package private) static CellcreateNextOnRowCol(Cell cell, long ts, byte type) static CellDeep clones the given cell if the cell supports deep cloningstatic booleanequalsIgnoreMvccVersion(Cell a, Cell b) special case for Cell.equalsstatic intEstimate based on keyvalue's serialization format in the RPC layer.static intCalculates the serialized key size.static ByteRangefillFamilyRange(Cell cell, ByteRange range) static ByteRangefillQualifierRange(Cell cell, ByteRange range) static ByteRangefillRowRange(Cell cell, ByteRange range) ByteRangestatic ByteRangefillTagRange(Cell cell, ByteRange range) static ByteRangefillValueRange(Cell cell, ByteRange range) static intfindCommonPrefixInFlatKey(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 bytegetQualifierByte(Cell cell, int index) static intgetRowAsInt(Cell cell) Converts the rowkey bytes of the given cell into an int valuestatic bytegetRowByte(Cell cell, int index) miscRetrieve Cell's first tag, matching the passed in typeReturn tags in the given Cell as a Liststatic BigDecimalgetValueAsBigDecimal(Cell cell) Converts the value bytes of the given cell into a BigDecimalstatic doublegetValueAsDouble(Cell cell) Converts the value bytes of the given cell into a double valuestatic intgetValueAsInt(Cell cell) Converts the value bytes of the given cell into a int valuestatic longgetValueAsLong(Cell cell) Converts the value bytes of the given cell into a long valuestatic ByteBufferstatic booleanisDelete(byte type) Return true if a delete type, aKeyValue.Type.Deleteor a {KeyValue.Type#DeleteFamily} or aKeyValue.Type.DeleteColumnKeyValue type.static booleanisDeleteColumnOrFamily(Cell cell) Returns True if this cell is a delete family or column type.static booleanisDeleteColumns(Cell cell) static booleanisDeleteColumnVersion(Cell cell) static booleanisDeleteFamily(Cell cell) static booleanisDeleteFamilyVersion(Cell cell) static booleanisDeleteType(Cell cell) Returns True if this cell is aKeyValue.Type.Deletetype.static booleanmatchingColumn(Cell left, byte[] fam, int foffset, int flength, byte[] qual, int qoffset, int qlength) static booleanmatchingFamily(Cell left, byte[] buf, int offset, int length) static booleanmatchingQualifier(Cell left, byte[] buf, int offset, int length) Finds if the qualifier part of the cell and the KV serialized byte[] are equalstatic booleanmatchingRows(Cell left, byte[] buf, int offset, int length) static booleanmatchingTags(Cell left, Cell right, int llength, int rlength) static booleanmatchingType(Cell a, Cell b) static booleanmatchingValue(Cell left, Cell right, int lvlength, int rvlength) static booleanoverlappingKeys(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 booleanqualifierStartsWith(Cell left, byte[] startsWith) Finds if the start of the qualifier part of the Cell matchesbufstatic voidsetSequenceId(Cell cell, long seqId) Sets the given seqId to the cell.static voidsetTimestamp(Cell cell, byte[] ts) Sets the given timestamp to the cell.static voidsetTimestamp(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.TypetoType(byte type) static KeyValue.TypetoTypeByte(Cell.Type type) static booleanupdateLatestStamp(Cell cell, byte[] ts) Sets the given timestamp to the cell iff current timestamp isHConstants.LATEST_TIMESTAMP.static booleanupdateLatestStamp(Cell cell, long ts) Sets the given timestamp to the cell iff current timestamp isHConstants.LATEST_TIMESTAMP.static intwriteCell(Cell cell, OutputStream out, boolean withTags) Writes the cell to the given OutputStreamstatic voidwriteCellToBuffer(Cell cell, ByteBuffer buf, int offset) Writes a cell to the buffer at the given offsetstatic voidwriteFamily(OutputStream out, Cell cell, byte flength) Writes the family from the given cell to the output streamstatic voidwriteFlatKey(Cell cell, DataOutput out) Writes the Cell's key part as it would have serialized in a KeyValue.static intwriteFlatKey(Cell cell, OutputStream out) static voidwriteQualifier(OutputStream out, Cell cell, int qlength) Writes the qualifier from the given cell to the output streamstatic voidwriteQualifierSkippingBytes(DataOutputStream out, Cell cell, int qlength, int commonPrefix) Writes the qualifier from the given cell to the output stream excluding the common prefixstatic voidwriteRow(OutputStream out, Cell cell, short rlength) Writes the row from the given cell to the output streamstatic voidwriteRowKeyExcludingCommon(Cell cell, short rLen, int commonPrefix, DataOutputStream out) Write rowkey excluding the common part.static voidwriteRowSkippingBytes(DataOutputStream out, Cell cell, short rlength, int commonPrefix) Writes the row from the given cell to the output stream excluding the common prefixstatic voidwriteTags(OutputStream out, Cell cell, int tagsLength) Writes the tag from the given cell to the output streamstatic voidwriteValue(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.Deleteor a {KeyValue.Type#DeleteFamily} or aKeyValue.Type.DeleteColumnKeyValue type. -
isDeleteType
Returns True if this cell is aKeyValue.Type.Deletetype. -
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- theCellComparatorto 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- theCellComparatorto 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- theCellComparatorto 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- theCellComparatorto 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- theCellComparatorto 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- theCellComparatorto 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
cellsize 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.
-