Package org.apache.hadoop.hbase
Class KeyValueUtil
java.lang.Object
org.apache.hadoop.hbase.KeyValueUtil
static convenience methods for dealing with KeyValues and collections of KeyValues
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intappendKeyTo(ExtendedCell cell, byte[] output, int offset) static intappendKeyTo(ExtendedCell cell, ByteBuffer buf, int offset) static intappendTo(ExtendedCell cell, ByteBuffer buf, int offset, boolean withTags) Copy the Cell content into the passed buf in KeyValue serialization format.static intappendToByteArray(ExtendedCell cell, byte[] output, int offset, boolean withTags) copy key and valuestatic voidappendToByteBuffer(ByteBuffer bb, KeyValue kv, boolean includeMvccVersion) (package private) static StringbytesToHex(byte[] buf, int offset, int length) (package private) static voidcheckKeyValueBytes(byte[] buf, int offset, int length, boolean withTags) private static intcheckKeyValueTagBytes(byte[] buf, int offset, int length, int pos, int endOffset) static ByteBufferThe position will be set to the beginning of the new ByteBufferstatic byte[]static KeyValuecopy the cell to create a new keyvaluestatic KeyValueCreate a KeyValue readinglengthfrominstatic KeyValueWhere to read bytes from.static KeyValuecreateFirstOnRow(byte[] row) Create a KeyValue that is smaller than all other possible KeyValues for the given row.static KeyValuecreateFirstOnRow(byte[] row, byte[] family, byte[] qualifier) Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row,family,qualifier.static KeyValuecreateFirstOnRow(byte[] buffer, byte[] row, byte[] family, byte[] qualifier) Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier.static KeyValuecreateFirstOnRow(byte[] row, byte[] f, byte[] q, long ts) Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier.static KeyValuecreateFirstOnRow(byte[] buffer, int boffset, byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength) Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier.static KeyValuecreateFirstOnRow(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength) Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier.static KeyValuecreateFirstOnRow(byte[] row, int roffset, short rlength) Create a KeyValue that is smaller than all other possible KeyValues for the given row.static KeyValuecreateFirstOnRow(byte[] row, long ts) Creates a KeyValue that is smaller than all other KeyValues that are older than the passed timestamp.static KeyValuecreateKeyValueFromInputStream(InputStream in, boolean withTags) Create a KeyValue reading from the raw InputStream.static KeyValuecreateKeyValueFromKey(byte[] b) Returns a KeyValue made of a byte array that holds the key-only part.static KeyValuecreateKeyValueFromKey(byte[] b, int o, int l) Return a KeyValue made of a byte array that holds the key-only part.static KeyValueReturn a KeyValue made of a byte buffer that holds the key-only part.static KeyValuecreateLastOnRow(byte[] row) Creates a KeyValue that is last on the specified row id.static KeyValuecreateLastOnRow(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength) Create a KeyValue for the specified row, family and qualifier that would be larger than or equal to all other possible KeyValues that have the same row, family, qualifier.static KeyValueensureKeyValue(ExtendedCell cell) Deprecated.without any replacement.ensureKeyValues(List<ExtendedCell> cells) Deprecated.private static intkeyLength(short rlen, byte flen, int qlen) static intReturns number of bytes this cell's key part would have been used if serialized as inKeyValue.static intlength(short rlen, byte flen, int qlen, int vlen, int tlen, boolean withTags) lengthstatic intlengthWithMvccVersion(KeyValue kv, boolean includeMvccVersion) static KeyValuenextShallowCopy(ByteBuffer bb, boolean includesMvccVersion, boolean includesTags) Creates a new KeyValue object positioned in the supplied ByteBuffer and sets the ByteBuffer's position to the start of the next KeyValue.static KeyValuepreviousKey(KeyValue in) Decrement the timestamp.static KeyValuetoNewKeyCell(ExtendedCell cell) Copies the key to a new KeyValuestatic inttotalLengthWithMvccVersion(Iterable<? extends KeyValue> kvs, boolean includeMvccVersion) static longwrite(KeyValue kv, DataOutput out) Write out a KeyValue in the manner in which we used to when KeyValue was a Writable.
-
Field Details
-
LOG
-
-
Constructor Details
-
KeyValueUtil
public KeyValueUtil()
-
-
Method Details
-
length
length -
keyLength
Returns number of bytes this cell's key part would have been used if serialized as inKeyValue. Key includes rowkey, family, qualifier, timestamp and type.- Returns:
- the key length
-
keyLength
-
lengthWithMvccVersion
-
totalLengthWithMvccVersion
public static int totalLengthWithMvccVersion(Iterable<? extends KeyValue> kvs, boolean includeMvccVersion) -
copyToNewKeyValue
copy the cell to create a new keyvalue -
copyKeyToNewByteBuffer
The position will be set to the beginning of the new ByteBuffer- Returns:
- the Bytebuffer containing the key part of the cell
-
toNewKeyCell
Copies the key to a new KeyValue- Returns:
- the KeyValue that consists only the key part of the incoming cell
-
copyToNewByteArray
-
appendKeyTo
-
appendToByteArray
copy key and value -
appendTo
Copy the Cell content into the passed buf in KeyValue serialization format. -
appendKeyTo
-
appendToByteBuffer
-
nextShallowCopy
public static KeyValue nextShallowCopy(ByteBuffer bb, boolean includesMvccVersion, boolean includesTags) Creates a new KeyValue object positioned in the supplied ByteBuffer and sets the ByteBuffer's position to the start of the next KeyValue. Does not allocate a new array or copy data. -
previousKey
Decrement the timestamp. For tests (currently wasteful) Remember timestamps are sorted reverse chronologically.- Returns:
- previous key
-
createLastOnRow
public static KeyValue createLastOnRow(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength) Create a KeyValue for the specified row, family and qualifier that would be larger than or equal to all other possible KeyValues that have the same row, family, qualifier. Used for reseeking. Should NEVER be returned to a client. row key row offset row length family name family offset family length column qualifier qualifier offset qualifier length- Returns:
- Last possible key on passed row, family, qualifier.
-
createFirstOnRow
Create a KeyValue that is smaller than all other possible KeyValues for the given row. That is any (valid) KeyValue on 'row' would sort _after_ the result.- Parameters:
row- - row key (arbitrary byte array)- Returns:
- First possible KeyValue on passed
row
-
createLastOnRow
Creates a KeyValue that is last on the specified row id. That is, every other possible KeyValue for the given row would compareTo() less than the result of this call.- Parameters:
row- row key- Returns:
- Last possible KeyValue on passed
row
-
createFirstOnRow
Create a KeyValue that is smaller than all other possible KeyValues for the given row. That is any (valid) KeyValue on 'row' would sort _after_ the result.- Parameters:
row- - row key (arbitrary byte array)- Returns:
- First possible KeyValue on passed
row
-
createFirstOnRow
Creates a KeyValue that is smaller than all other KeyValues that are older than the passed timestamp.- Parameters:
row- - row key (arbitrary byte array)ts- - timestamp- Returns:
- First possible key on passed
rowand timestamp.
-
createFirstOnRow
Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row,family,qualifier. Used for seeking.- Parameters:
row- - row key (arbitrary byte array)family- - family namequalifier- - column qualifier- Returns:
- First possible key on passed
row, and column.
-
createFirstOnRow
Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier. Used for seeking.- Parameters:
row- - row key (arbitrary byte array)f- - family nameq- - column qualifierts- - timestamp- Returns:
- First possible key on passed
row, column and timestamp
-
createFirstOnRow
public static KeyValue createFirstOnRow(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength) Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier. Used for seeking.- Parameters:
row- row keyroffset- row offsetrlength- row lengthfamily- family namefoffset- family offsetflength- family lengthqualifier- column qualifierqoffset- qualifier offsetqlength- qualifier length- Returns:
- First possible key on passed Row, Family, Qualifier.
-
createFirstOnRow
public static KeyValue createFirstOnRow(byte[] buffer, byte[] row, byte[] family, byte[] qualifier) throws IllegalArgumentException Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier. Used for seeking.- Parameters:
buffer- the buffer to use for the newKeyValueobjectrow- the value keyfamily- family namequalifier- column qualifier- Returns:
- First possible key on passed Row, Family, Qualifier.
- Throws:
IllegalArgumentException- The resultingKeyValueobject would be larger than the provided buffer or thanInteger.MAX_VALUE
-
createFirstOnRow
public static KeyValue createFirstOnRow(byte[] buffer, int boffset, byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength) throws IllegalArgumentException Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier. Used for seeking.- Parameters:
buffer- the buffer to use for the newKeyValueobjectboffset- buffer offsetrow- the value keyroffset- row offsetrlength- row lengthfamily- family namefoffset- family offsetflength- family lengthqualifier- column qualifierqoffset- qualifier offsetqlength- qualifier length- Returns:
- First possible key on passed Row, Family, Qualifier.
- Throws:
IllegalArgumentException- The resultingKeyValueobject would be larger than the provided buffer or thanInteger.MAX_VALUE
-
ensureKeyValue
Deprecated.without any replacement.- Returns:
cellif it is an object of classKeyValueelse we will return a newKeyValueinstance made fromcellNote: Even if the cell is an object of any of the subclass ofKeyValue, we will create a newKeyValueobject wrapping same buffer. This API is used only with MR based tools which expect the type to be exactly KeyValue. That is the reason for doing this way.
-
ensureKeyValues
Deprecated. -
write
Write out a KeyValue in the manner in which we used to when KeyValue was a Writable.- Returns:
- Length written on stream
- Throws:
IOException- See Also:
-
bytesToHex
-
checkKeyValueBytes
-
checkKeyValueTagBytes
private static int checkKeyValueTagBytes(byte[] buf, int offset, int length, int pos, int endOffset) -
createKeyValueFromInputStream
public static KeyValue createKeyValueFromInputStream(InputStream in, boolean withTags) throws IOException Create a KeyValue reading from the raw InputStream. NamedcreateKeyValueFromInputStreamso doesn't clash withcreate(DataInput)- Parameters:
in- inputStream to read.withTags- whether the keyvalue should include tags are not- Returns:
- Created KeyValue OR if we find a length of zero, we will return null which can be useful marking a stream as done.
- Throws:
IOException
-
createKeyValueFromKey
Returns a KeyValue made of a byte array that holds the key-only part. Needed to convert hfile index members to KeyValues. -
createKeyValueFromKey
Return a KeyValue made of a byte buffer that holds the key-only part. Needed to convert hfile index members to KeyValues. -
createKeyValueFromKey
Return a KeyValue made of a byte array that holds the key-only part. Needed to convert hfile index members to KeyValues. -
create
Where to read bytes from. Creates a byte array to hold the KeyValue backing bytes copied from the steam.- Returns:
- KeyValue created by deserializing from
inOR if we find a length of zero, we will return null which can be useful marking a stream as done. - Throws:
IOException
-
create
Create a KeyValue readinglengthfromin- Returns:
- Created KeyValue OR if we find a length of zero, we will return null which can be useful marking a stream as done.
- Throws:
IOException
-