Class KeyValue
- All Implemented Interfaces:
Cloneable,Cell,ExtendedCell,HeapSize,RawCell
- Direct Known Subclasses:
KeyValue.KeyOnlyKeyValue,NoTagsKeyValue,SizeCachedKeyValue
HBase applications and users should use the Cell interface and avoid directly using KeyValue and member functions not defined in Cell.
If being used client-side, the primary methods to access individual fields are
getRowArray(), getFamilyArray(), getQualifierArray(),
getTimestamp(), and getValueArray(). These methods allocate new byte arrays and
return copies. Avoid their use server-side.
Instances of this class are immutable. They do not implement Comparable but Comparators are provided. Comparators change with context, whether user table or a catalog table comparison. Its critical you use the appropriate comparator. There are Comparators for normal HFiles, Meta's Hfiles, and bloom filter keys.
KeyValue wraps a byte array and takes offsets and lengths into passed array at where to start
interpreting the content as KeyValue. The KeyValue format inside a byte array is:
<keylength> <valuelength> <key> <value> Key is further
decomposed as: <rowlength> <row> <columnfamilylength>
<columnfamily> <columnqualifier>
<timestamp> <keytype> The rowlength maximum is
Short.MAX_SIZE, column family length maximum is Byte.MAX_SIZE, and
column qualifier + key length must be < Integer.MAX_SIZE. The column does not
contain the family/qualifier delimiter, COLUMN_FAMILY_DELIMITER
KeyValue can optionally contain Tags. When it contains tags, it is added in the byte array after
the value part. The format for this part is: <tagslength><tagsbytes>.
tagslength maximum is Short.MAX_SIZE. The tagsbytes
contain one or more tags where as each tag is of the form
<taglength><tagtype><tagbytes>. tagtype is one byte
and taglength maximum is Short.MAX_SIZE and it includes 1 byte type
length and actual tag bytes length.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA simple form of KeyValue that creates a keyvalue with only the key part of the byte[] Mainly used in places where we need to compare two cells.static classDeprecated.static classDeprecated.:MetaCellComparator.META_COMPARATORto be used.static interfaceAvoids redundant comparisons for better performance.static enumKey type. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]static final byte[]static final charColon character in UTF-8static final KeyValue.KVComparatorDeprecated.UseCellComparator.getInstance()instead.static final intSize of the family length field in bytesstatic final intstatic final intstatic final intSize of the key length field in bytesstatic final intstatic final intprotected intprivate static final org.slf4j.Loggerstatic final KeyValueLowest possible key.static final KeyValue.KVComparatorDeprecated.UseMetaCellComparator.META_COMPARATORinstead.protected intstatic final intstatic final intSize of the row length field in bytesstatic final intprivate longstatic final intSize of the tags length field in bytesstatic final intSize of the timestamp field in bytesstatic final intstatic final intSize of the key type field in bytesFields inherited from interface org.apache.hadoop.hbase.ExtendedCell
CELL_NOT_BASED_ON_CHUNKFields inherited from interface org.apache.hadoop.hbase.RawCell
MAX_TAGS_LENGTH -
Constructor Summary
ConstructorsConstructorDescriptionKeyValue()Writable Constructor -- DO NOT USEKeyValue(byte[] bytes) Creates a KeyValue from the start of the specified byte array.KeyValue(byte[] row, byte[] family, byte[] qualifier) Constructs KeyValue structure filled with null value.KeyValue(byte[] row, byte[] family, byte[] qualifier, byte[] value) Constructs KeyValue structure as a put filled with specified values and LATEST_TIMESTAMP.KeyValue(byte[] row, byte[] family, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, byte[] tags) KeyValue(byte[] row, byte[] family, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, List<Tag> tags) Constructs KeyValue structure filled with specified values.KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, byte[] value) Constructs KeyValue structure filled with specified values.Constructs KeyValue structure filled with specified values.Constructs KeyValue structure filled with specified values.KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type) Constructs KeyValue structure filled with specified values.KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type, byte[] value) Constructs KeyValue structure filled with specified values.KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type, byte[] value, byte[] tags) Constructs KeyValue structure filled with specified values.KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type, byte[] value, List<Tag> tags) Constructs KeyValue structure filled with specified values.KeyValue(byte[] bytes, int offset) Creates a KeyValue from the specified byte array and offset.KeyValue(byte[] buffer, int boffset, byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, Tag[] tags) Constructs KeyValue structure filled with specified values.KeyValue(byte[] bytes, int offset, int length) Creates a KeyValue from the specified byte array, starting at offset, and for lengthlength.KeyValue(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength) Constructs KeyValue structure filled with specified values.KeyValue(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, byte[] tags, int tagsOffset, int tagsLength) KeyValue(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, List<Tag> tags) Constructs KeyValue structure filled with specified values.KeyValue(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, ByteBuffer qualifier, long ts, KeyValue.Type type, ByteBuffer value, List<Tag> tags) KeyValue(byte[] bytes, int offset, int length, long ts) Creates a KeyValue from the specified byte array, starting at offset, and for lengthlength.KeyValue(byte[] row, long timestamp) Constructs KeyValue structure filled with null value.KeyValue(byte[] row, long timestamp, KeyValue.Type type) Constructs KeyValue structure filled with null value.KeyValue(int rlength, int flength, int qlength, long timestamp, KeyValue.Type type, int vlength) Constructs an empty KeyValue structure, with specified sizes.KeyValue(int rlength, int flength, int qlength, long timestamp, KeyValue.Type type, int vlength, int tagsLength) Constructs an empty KeyValue structure, with specified sizes. -
Method Summary
Modifier and TypeMethodDescriptionprivate intcalculateHashForKey(Cell cell) (package private) static voidcheckParameters(byte[] row, int rlength, byte[] family, int flength, int qlength, int vlength) Checks the parameters passed to a constructor.clone()Clones a KeyValue.static KeyValueCreate a KeyValue readinglengthfrominstatic KeyValueCreate a KeyValue reading frominprivate static byte[]createByteArray(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, byte[] tags, int tagsOffset, int tagsLength) Write KeyValue format into a byte array.private static byte[]createByteArray(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, Object qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, Object value, int voffset, int vlength, List<Tag> tags) private static byte[]createEmptyByteArray(int rlength, int flength, int qlength, long timestamp, KeyValue.Type type, int vlength, int tagsLength) Create an empty byte[] representing a KeyValue All lengths are preset and can be filled in later.createKeyOnly(boolean lenAsVal) Creates a new KeyValue that only contains the key portion (the value is set to be null).Does a deep copy of the contents to a new memory area and returns it as a new cell.booleanNeeded doing 'contains' on List.byte[]To be used only in tests where the Cells are clearly assumed to be of type KeyValue and that we need access to the backing array to do some test case related assertions.static intgetDelimiter(byte[] b, int offset, int length, int delimiter) Find index of passed delimiter walking from start of buffer forwards.static intgetDelimiterInReverse(byte[] b, int offset, int length, int delimiter) Find index of passed delimiter walking from end of buffer backwards.byte[]Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)byteReturns Family lengthbytegetFamilyLength(int famLenPos) Returns Family length(package private) intgetFamilyLengthPosition(int rowLength) intReturns Family offset(package private) intgetFamilyOffset(int familyLenPosition) Returns Family offsetbyte[]getKey()Do not use unless you have to.static longgetKeyDataStructureSize(int rlength, int flength, int qlength) Computes the number of bytes that aKeyValueinstance with the provided characteristics would take up in its underlying data structure for the key.intReturns Length of key portion.intReturns Key offset in backing buffer..static longgetKeyValueDataStructureSize(int klength, int vlength, int tagsLength) Computes the number of bytes that aKeyValueinstance with the provided characteristics would take up for its underlying data structure.static longgetKeyValueDataStructureSize(int rlength, int flength, int qlength, int vlength) Computes the number of bytes that aKeyValueinstance with the provided characteristics would take up for its underlying data structure.static longgetKeyValueDataStructureSize(int rlength, int flength, int qlength, int vlength, int tagsLength) Computes the number of bytes that aKeyValueinstance with the provided characteristics would take up for its underlying data structure.intReturns Length of bytes this KeyValue occupies ingetBuffer().private static intgetLength(byte[] bytes, int offset) Determines the total length of the KeyValue stored in the specified byte array and offset.intReturns Offset intogetBuffer()at which this KeyValue starts.byte[]Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)intReturns Qualifier lengthprivate intgetQualifierLength(int rlength, int flength) Returns Qualifier length(package private) intgetQualifierLength(int keyLength, int rlength, int flength) Returns Qualifier lengthintReturns Qualifier offsetprivate intgetQualifierOffset(int foffset) Returns Qualifier offset(package private) intgetQualifierOffset(int foffset, int flength) Returns Qualifier offsetbyte[]Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)shortReturns Row lengthintReturns Row offsetlongused to achieve atomic operations in the memstore.intReturns Serialized size (defaults to include tag length).intgetSerializedSize(boolean withTags) KeyValue formatbyte[]Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)intReturn the total length of the tag bytesintReturn the offset where the tag data starts.longReturn the timestamp.(package private) longgetTimestamp(int keylength) Return the timestamp.intReturns Timestamp offsetprivate intgetTimestampOffset(int keylength) Return the timestamp offsetbyteReturns KeyValue.TYPE byte representation(package private) bytegetTypeByte(int keyLength) Return the KeyValue.TYPE byte representationbyte[]Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)intReturns Value lengthintReturns the value offsetinthashCode()In line withequals(Object), only uses the key portion, not the value.longheapSize()HeapSize implementationstatic StringhumanReadableTimestamp(long timestamp) booleanReturns True if this KeyValue has a LATEST_TIMESTAMP timestamp.static StringkeyToString(byte[] k) Return key as a String, empty string if k is null.static StringkeyToString(byte[] b, int o, int l) Use for logging.static longoswrite(KeyValue kv, OutputStream out, boolean withTags) Deprecated.As of release 2.0.0, this will be removed in HBase 3.0.0.voidsetSequenceId(long seqId) Sets with the given seqId.voidsetTimestamp(byte[] ts) Sets with the given timestamp.voidsetTimestamp(long ts) Sets with the given timestamp.Creates a shallow copy of this KeyValue, reusing the data byte buffer.toString()Produces a string map for this key/value pair.booleanupdateLatestStamp(byte[] now) Update the timestamp.intwrite(OutputStream out, boolean withTags) Write this cell to an OutputStream in aKeyValueformat.voidwrite(ByteBuffer buf, int offset) Write this Cell into the given buf's offset in aKeyValueformat.static longwrite(KeyValue kv, DataOutput out) Write out a KeyValue in the manner in which we used to when KeyValue was a Writable.static intwriteByteArray(byte[] buffer, int boffset, byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, Tag[] tags) Write KeyValue format into the provided byte array.Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.hadoop.hbase.ExtendedCell
getChunkId
-
Field Details
-
LOG
-
FIXED_OVERHEAD
-
COLUMN_FAMILY_DELIMITER
Colon character in UTF-8- See Also:
-
COLUMN_FAMILY_DELIM_ARRAY
-
COMPARATOR
Deprecated.UseCellComparator.getInstance()instead. Deprecated for hbase 2.0, remove for hbase 3.0.Comparator for plain key/values; i.e. non-catalog table key/values. Works on Key portion of KeyValue only. -
META_COMPARATOR
Deprecated.UseMetaCellComparator.META_COMPARATORinstead. Deprecated for hbase 2.0, remove for hbase 3.0. -
KEY_LENGTH_SIZE
Size of the key length field in bytes- See Also:
-
TYPE_SIZE
Size of the key type field in bytes- See Also:
-
ROW_LENGTH_SIZE
Size of the row length field in bytes- See Also:
-
FAMILY_LENGTH_SIZE
Size of the family length field in bytes- See Also:
-
TIMESTAMP_SIZE
Size of the timestamp field in bytes- See Also:
-
TIMESTAMP_TYPE_SIZE
- See Also:
-
KEY_INFRASTRUCTURE_SIZE
- See Also:
-
ROW_OFFSET
- See Also:
-
ROW_KEY_OFFSET
- See Also:
-
KEYVALUE_INFRASTRUCTURE_SIZE
- See Also:
-
TAGS_LENGTH_SIZE
Size of the tags length field in bytes- See Also:
-
KEYVALUE_WITH_TAGS_INFRASTRUCTURE_SIZE
- See Also:
-
LOWESTKEY
Lowest possible key. Makes a Key with highest possible Timestamp, empty row and column. No key can be equal or lower than this one in memstore or in store file. -
bytes
-
offset
-
length
-
seqId
-
-
Constructor Details
-
KeyValue
public KeyValue()Writable Constructor -- DO NOT USE -
KeyValue
Creates a KeyValue from the start of the specified byte array. Presumesbytescontent is formatted as a KeyValue blob.- Parameters:
bytes- byte array
-
KeyValue
Creates a KeyValue from the specified byte array and offset. Presumesbytescontent starting atoffsetis formatted as a KeyValue blob.- Parameters:
bytes- byte arrayoffset- offset to start of KeyValue
-
KeyValue
Creates a KeyValue from the specified byte array, starting at offset, and for lengthlength.- Parameters:
bytes- byte arrayoffset- offset to start of the KeyValuelength- length of the KeyValue
-
KeyValue
Creates a KeyValue from the specified byte array, starting at offset, and for lengthlength.- Parameters:
bytes- byte arrayoffset- offset to start of the KeyValuelength- length of the KeyValuets- timestamp
-
KeyValue
Constructs KeyValue structure filled with null value. Sets type toKeyValue.Type.Maximum- Parameters:
row- - row key (arbitrary byte array)timestamp- version timestamp
-
KeyValue
Constructs KeyValue structure filled with null value.- Parameters:
row- - row key (arbitrary byte array)timestamp- version timestamp
-
KeyValue
Constructs KeyValue structure filled with null value. Sets type toKeyValue.Type.Maximum- Parameters:
row- - row key (arbitrary byte array)family- family namequalifier- column qualifier
-
KeyValue
Constructs KeyValue structure as a put filled with specified values and LATEST_TIMESTAMP.- Parameters:
row- - row key (arbitrary byte array)family- family namequalifier- column qualifier
-
KeyValue
Constructs KeyValue structure filled with specified values.- Parameters:
row- row keyfamily- family namequalifier- column qualifiertimestamp- version timestamptype- key type- Throws:
IllegalArgumentException- an illegal value was passed
-
KeyValue
Constructs KeyValue structure filled with specified values.- Parameters:
row- row keyfamily- family namequalifier- column qualifiertimestamp- version timestampvalue- column value- Throws:
IllegalArgumentException- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, byte[] value, Tag[] tags) Constructs KeyValue structure filled with specified values.- Parameters:
row- row keyfamily- family namequalifier- column qualifiertimestamp- version timestampvalue- column valuetags- tags- Throws:
IllegalArgumentException- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, byte[] value, List<Tag> tags) Constructs KeyValue structure filled with specified values.- Parameters:
row- row keyfamily- family namequalifier- column qualifiertimestamp- version timestampvalue- column valuetags- tags non-empty list of tags or null- Throws:
IllegalArgumentException- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type, byte[] value) Constructs KeyValue structure filled with specified values.- Parameters:
row- row keyfamily- family namequalifier- column qualifiertimestamp- version timestamptype- key typevalue- column value- Throws:
IllegalArgumentException- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type, byte[] value, List<Tag> tags) Constructs KeyValue structure filled with specified values.Column is split into two fields, family and qualifier.
- Parameters:
row- row keyfamily- family namequalifier- column qualifiertimestamp- version timestamptype- key typevalue- column value- Throws:
IllegalArgumentException- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type, byte[] value, byte[] tags) Constructs KeyValue structure filled with specified values.- Parameters:
row- row keyfamily- family namequalifier- column qualifiertimestamp- version timestamptype- key typevalue- column value- Throws:
IllegalArgumentException- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, byte[] family, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, List<Tag> tags) Constructs KeyValue structure filled with specified values.- Parameters:
row- row keyfamily- family namequalifier- column qualifierqoffset- qualifier offsetqlength- qualifier lengthtimestamp- version timestamptype- key typevalue- column valuevoffset- value offsetvlength- value length- Throws:
IllegalArgumentException- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, byte[] family, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, byte[] tags) - Parameters:
row- row keyfamily- family namequalifier- qualifier nameqoffset- qualifier offsetqlength- qualifier lengthtimestamp- version timestamptype- key typevalue- column valuevoffset- value offsetvlength- value lengthtags- tags
-
KeyValue
public KeyValue(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength) Constructs KeyValue structure filled with specified values.Column is split into two fields, family and qualifier.
- Parameters:
row- row key- Throws:
IllegalArgumentException- an illegal value was passed
-
KeyValue
public KeyValue(byte[] buffer, int boffset, byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, Tag[] tags) Constructs KeyValue structure filled with specified values. Uses the provided buffer as the data buffer.Column is split into two fields, family and qualifier.
- Parameters:
buffer- the bytes buffer to useboffset- buffer offsetrow- row keyroffset- row offsetrlength- row lengthfamily- family namefoffset- family offsetflength- family lengthqualifier- column qualifierqoffset- qualifier offsetqlength- qualifier lengthtimestamp- version timestamptype- key typevalue- column valuevoffset- value offsetvlength- value lengthtags- non-empty list of tags or null- Throws:
IllegalArgumentException- an illegal value was passed or there is insufficient space remaining in the buffer
-
KeyValue
public KeyValue(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, List<Tag> tags) Constructs KeyValue structure filled with specified values.Column is split into two fields, family and qualifier.
- Parameters:
row- row keyroffset- row offsetrlength- row lengthfamily- family namefoffset- family offsetflength- family lengthqualifier- column qualifierqoffset- qualifier offsetqlength- qualifier lengthtimestamp- version timestamptype- key typevalue- column valuevoffset- value offsetvlength- value lengthtags- tags- Throws:
IllegalArgumentException- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, byte[] tags, int tagsOffset, int tagsLength) - Parameters:
row- row keyroffset- row offsetrlength- row lengthfamily- family namefoffset- fammily offsetflength- family lengthqualifier- column qualifierqoffset- qualifier offsetqlength- qualifier lengthtimestamp- version timestamptype- key typevalue- column valuevoffset- value offsetvlength- value lengthtags- input tags
-
KeyValue
public KeyValue(int rlength, int flength, int qlength, long timestamp, KeyValue.Type type, int vlength) Constructs an empty KeyValue structure, with specified sizes. This can be used to partially fill up KeyValues.Column is split into two fields, family and qualifier.
- Parameters:
rlength- row lengthflength- family lengthqlength- qualifier lengthtimestamp- version timestamptype- key typevlength- value length- Throws:
IllegalArgumentException- an illegal value was passed
-
KeyValue
public KeyValue(int rlength, int flength, int qlength, long timestamp, KeyValue.Type type, int vlength, int tagsLength) Constructs an empty KeyValue structure, with specified sizes. This can be used to partially fill up KeyValues.Column is split into two fields, family and qualifier.
- Parameters:
rlength- row lengthflength- family lengthqlength- qualifier lengthtimestamp- version timestamptype- key typevlength- value lengthtagsLength- length of the tags- Throws:
IllegalArgumentException- an illegal value was passed
-
KeyValue
public KeyValue(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, ByteBuffer qualifier, long ts, KeyValue.Type type, ByteBuffer value, List<Tag> tags) -
KeyValue
-
-
Method Details
-
getKeyValueDataStructureSize
Computes the number of bytes that aKeyValueinstance with the provided characteristics would take up for its underlying data structure.- Parameters:
rlength- row lengthflength- family lengthqlength- qualifier lengthvlength- value length- Returns:
- the
KeyValuedata structure length
-
getKeyValueDataStructureSize
public static long getKeyValueDataStructureSize(int rlength, int flength, int qlength, int vlength, int tagsLength) Computes the number of bytes that aKeyValueinstance with the provided characteristics would take up for its underlying data structure.- Parameters:
rlength- row lengthflength- family lengthqlength- qualifier lengthvlength- value lengthtagsLength- total length of the tags- Returns:
- the
KeyValuedata structure length
-
getKeyValueDataStructureSize
Computes the number of bytes that aKeyValueinstance with the provided characteristics would take up for its underlying data structure.- Parameters:
klength- key lengthvlength- value lengthtagsLength- total length of the tags- Returns:
- the
KeyValuedata structure length
-
getKeyDataStructureSize
Computes the number of bytes that aKeyValueinstance with the provided characteristics would take up in its underlying data structure for the key.- Parameters:
rlength- row lengthflength- family lengthqlength- qualifier length- Returns:
- the key data structure length
-
getSequenceId
used to achieve atomic operations in the memstore.- Specified by:
getSequenceIdin interfaceCell- Specified by:
getSequenceIdin interfaceExtendedCell- Returns:
- seqId (always > 0 if exists), or 0 if it no longer exists
-
setSequenceId
Description copied from interface:ExtendedCellSets with the given seqId.- Specified by:
setSequenceIdin interfaceExtendedCell- Parameters:
seqId- sequence ID
-
createEmptyByteArray
private static byte[] createEmptyByteArray(int rlength, int flength, int qlength, long timestamp, KeyValue.Type type, int vlength, int tagsLength) Create an empty byte[] representing a KeyValue All lengths are preset and can be filled in later.- Parameters:
rlength- row lengthflength- family lengthqlength- qualifier lengthtimestamp- version timestamptype- key typevlength- value length- Returns:
- The newly created byte array.
-
checkParameters
static void checkParameters(byte[] row, int rlength, byte[] family, int flength, int qlength, int vlength) throws IllegalArgumentException Checks the parameters passed to a constructor.- Parameters:
row- row keyrlength- row lengthfamily- family nameflength- family lengthqlength- qualifier lengthvlength- value length- Throws:
IllegalArgumentException- an illegal value was passed
-
writeByteArray
public static int writeByteArray(byte[] buffer, int boffset, byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, Tag[] tags) Write KeyValue format into the provided byte array.- Parameters:
buffer- the bytes buffer to useboffset- buffer offsetrow- row keyroffset- row offsetrlength- row lengthfamily- family namefoffset- family offsetflength- family lengthqualifier- column qualifierqoffset- qualifier offsetqlength- qualifier lengthtimestamp- version timestamptype- key typevalue- column valuevoffset- value offsetvlength- value length- Returns:
- The number of useful bytes in the buffer.
- Throws:
IllegalArgumentException- an illegal value was passed or there is insufficient space remaining in the buffer
-
createByteArray
private static byte[] createByteArray(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, byte[] tags, int tagsOffset, int tagsLength) Write KeyValue format into a byte array.- Parameters:
row- row keyroffset- row offsetrlength- row lengthfamily- family namefoffset- family offsetflength- family lengthqualifier- column qualifierqoffset- qualifier offsetqlength- qualifier lengthtimestamp- version timestamptype- key typevalue- column valuevoffset- value offsetvlength- value length- Returns:
- The newly created byte array.
-
createByteArray
private static byte[] createByteArray(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, Object qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, Object value, int voffset, int vlength, List<Tag> tags) - Parameters:
qualifier- can be a ByteBuffer or a byte[], or null.value- can be a ByteBuffer or a byte[], or null.
-
equals
Needed doing 'contains' on List. Only compares the key portion, not the value. -
hashCode
In line withequals(Object), only uses the key portion, not the value. -
calculateHashForKey
-
clone
Clones a KeyValue. This creates a copy, re-allocating the buffer.- Overrides:
clonein classObject- Returns:
- Fully copied clone of this KeyValue
- Throws:
CloneNotSupportedException- if cloning of keyValue is not supported
-
shallowCopy
Creates a shallow copy of this KeyValue, reusing the data byte buffer. http://en.wikipedia.org/wiki/Object_copy- Returns:
- Shallow copy of this KeyValue
-
toString
-
keyToString
Return key as a String, empty string if k is null. -
toStringMap
Produces a string map for this key/value pair. Useful for programmatic use and manipulation of the data stored in an WALKey, for example, printing as JSON. Values are left out due to their tendency to be large. If needed, they can be added manually.- Returns:
- the Map<String,?> containing data from this key
-
keyToString
Use for logging.- Parameters:
b- Key portion of a KeyValue.o- Offset to start of keyl- Length of key.- Returns:
- Key as a String.
-
humanReadableTimestamp
-
getBuffer
To be used only in tests where the Cells are clearly assumed to be of type KeyValue and that we need access to the backing array to do some test case related assertions.- Returns:
- The byte array backing this KeyValue.
-
getOffset
Returns Offset intogetBuffer()at which this KeyValue starts. -
getLength
Returns Length of bytes this KeyValue occupies ingetBuffer(). -
getLength
Determines the total length of the KeyValue stored in the specified byte array and offset. Includes all headers.- Parameters:
bytes- byte arrayoffset- offset to start of the KeyValue- Returns:
- length of entire KeyValue, in bytes
-
getKeyOffset
Returns Key offset in backing buffer.. -
getKeyString
-
getKeyLength
Returns Length of key portion. -
getValueArray
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)- Specified by:
getValueArrayin interfaceCell- Returns:
- The array containing the value bytes.
-
getValueOffset
Returns the value offset- Specified by:
getValueOffsetin interfaceCell
-
getValueLength
Returns Value length- Specified by:
getValueLengthin interfaceCell
-
getRowArray
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)- Specified by:
getRowArrayin interfaceCell- Returns:
- The array containing the row bytes.
-
getRowOffset
Returns Row offset- Specified by:
getRowOffsetin interfaceCell
-
getRowLength
Returns Row length- Specified by:
getRowLengthin interfaceCell
-
getFamilyArray
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)- Specified by:
getFamilyArrayin interfaceCell- Returns:
- the array containing the family bytes.
-
getFamilyOffset
Returns Family offset- Specified by:
getFamilyOffsetin interfaceCell
-
getFamilyOffset
Returns Family offset -
getFamilyLength
Returns Family length- Specified by:
getFamilyLengthin interfaceCell
-
getFamilyLength
Returns Family length -
getFamilyLengthPosition
-
getQualifierArray
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)- Specified by:
getQualifierArrayin interfaceCell- Returns:
- The array containing the qualifier bytes.
-
getQualifierOffset
Returns Qualifier offset- Specified by:
getQualifierOffsetin interfaceCell
-
getQualifierOffset
Returns Qualifier offset -
getQualifierOffset
Returns Qualifier offset -
getQualifierLength
Returns Qualifier length- Specified by:
getQualifierLengthin interfaceCell
-
getQualifierLength
Returns Qualifier length -
getQualifierLength
Returns Qualifier length -
getTimestampOffset
Returns Timestamp offset -
getTimestampOffset
Return the timestamp offset -
isLatestTimestamp
Returns True if this KeyValue has a LATEST_TIMESTAMP timestamp. -
updateLatestStamp
Update the timestamp.- Parameters:
now- Time to set intothisIFF timestamp ==HConstants.LATEST_TIMESTAMP(else, its a noop).- Returns:
- True is we modified this.
-
setTimestamp
Description copied from interface:ExtendedCellSets with the given timestamp.- Specified by:
setTimestampin interfaceExtendedCell- Parameters:
ts- timestamp
-
setTimestamp
Description copied from interface:ExtendedCellSets with the given timestamp.- Specified by:
setTimestampin interfaceExtendedCell- Parameters:
ts- buffer containing the timestamp value
-
getKey
Do not use unless you have to. Used internally for compacting and testing. UsegetRowArray(),getFamilyArray(),getQualifierArray(), andgetValueArray()if accessing a KeyValue client-side.- Returns:
- Copy of the key portion only.
-
getTimestamp
Return the timestamp.- Specified by:
getTimestampin interfaceCell
-
getTimestamp
Return the timestamp. -
getTypeByte
Returns KeyValue.TYPE byte representation- Specified by:
getTypeBytein interfaceCell- Specified by:
getTypeBytein interfaceExtendedCell
-
getTypeByte
Return the KeyValue.TYPE byte representation -
getTagsOffset
Return the offset where the tag data starts.- Specified by:
getTagsOffsetin interfaceCell- Specified by:
getTagsOffsetin interfaceExtendedCell
-
getTagsLength
Return the total length of the tag bytes- Specified by:
getTagsLengthin interfaceCell- Specified by:
getTagsLengthin interfaceExtendedCell- Returns:
- the total length of the tags in the Cell.
-
getTagsArray
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)- Specified by:
getTagsArrayin interfaceCell- Specified by:
getTagsArrayin interfaceExtendedCell- Returns:
- the tags byte array
-
createKeyOnly
Creates a new KeyValue that only contains the key portion (the value is set to be null). TODO only used by KeyOnlyFilter -- move there.- Parameters:
lenAsVal- replace value with the actual value length (false=empty)
-
getDelimiter
Find index of passed delimiter walking from start of buffer forwards.- Parameters:
b- the kv serialized byte[] to processdelimiter- input delimeter to fetch index from start- Returns:
- Index of delimiter having started from start of
bmoving rightward.
-
getDelimiterInReverse
Find index of passed delimiter walking from end of buffer backwards.- Parameters:
b- the kv serialized byte[] to processoffset- the offset in the byte[]length- the length in the byte[]delimiter- input delimeter to fetch index from end- Returns:
- Index of delimiter
-
create
Create a KeyValue reading fromin- Parameters:
in- 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- if any IO error happen
-
create
Create a KeyValue readinglengthfromin- Parameters:
length- length of the Keyin- Input to read from- 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- if any IO error happen
-
write
Write out a KeyValue in the manner in which we used to when KeyValue was a Writable.- Parameters:
kv- the KeyValue on which write is being requestedout- OutputStream to write keyValue to- Returns:
- Length written on stream
- Throws:
IOException- if any IO error happen- See Also:
-
oswrite
@Deprecated public static long oswrite(KeyValue kv, OutputStream out, boolean withTags) throws IOException Deprecated.As of release 2.0.0, this will be removed in HBase 3.0.0. Instead usewrite(OutputStream, boolean)Write out a KeyValue in the manner in which we used to when KeyValue was a Writable but do not require aDataOutput, just take plainOutputStreamNamedoswriteso does not clash withwrite(KeyValue, DataOutput)- Parameters:
kv- the KeyValue on which write is being requestedout- OutputStream to write keyValue towithTags- boolean value indicating write is with Tags or not- Returns:
- Length written on stream
- Throws:
IOException- if any IO error happen- See Also:
-
write
Description copied from interface:ExtendedCellWrite this cell to an OutputStream in aKeyValueformat.
KeyValue format
<4 bytes keylength> <4 bytes valuelength> <2 bytes rowlength> <row> <1 byte columnfamilylength> <columnfamily> <columnqualifier> <8 bytes timestamp> <1 byte keytype> <value> <2 bytes tagslength> <tags>- Specified by:
writein interfaceExtendedCell- Parameters:
out- Stream to which cell has to be writtenwithTags- Whether to write tags.- Returns:
- how many bytes are written.
- Throws:
IOException
-
getSerializedSize
Description copied from interface:ExtendedCellKeyValue format<4 bytes keylength> <4 bytes valuelength> <2 bytes rowlength> <row> <1 byte columnfamilylength> <columnfamily> <columnqualifier> <8 bytes timestamp> <1 byte keytype> <value> <2 bytes tagslength> <tags>- Specified by:
getSerializedSizein interfaceExtendedCell- Parameters:
withTags- Whether to write tags.- Returns:
- Bytes count required to serialize this Cell in a
KeyValueformat.
-
getSerializedSize
Description copied from interface:ExtendedCellReturns Serialized size (defaults to include tag length).- Specified by:
getSerializedSizein interfaceCell- Specified by:
getSerializedSizein interfaceExtendedCell
-
write
Description copied from interface:ExtendedCellWrite this Cell into the given buf's offset in aKeyValueformat.- Specified by:
writein interfaceExtendedCell- Parameters:
buf- The buffer where to write the Cell.offset- The offset within buffer, to write the Cell.
-
heapSize
HeapSize implementation We do not count the bytes in the rowCache because it should be empty for a KeyValue in the MemStore. -
deepClone
Description copied from interface:ExtendedCellDoes a deep copy of the contents to a new memory area and returns it as a new cell.- Specified by:
deepClonein interfaceExtendedCell- Returns:
- The deep cloned cell
-
CellComparatorImpl.