@InterfaceAudience.Private public class KeyValue extends Object implements ExtendedCell, Cloneable
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.
Modifier and Type | Class and Description |
---|---|
static class |
KeyValue.KeyOnlyKeyValue
A 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 class |
KeyValue.KVComparator
Deprecated.
: Use
CellComparatorImpl . Deprecated for hbase 2.0, remove for hbase 3.0. |
static class |
KeyValue.MetaComparator
Deprecated.
:
MetaCellComparator.META_COMPARATOR to be used. Deprecated for hbase 2.0,
remove for hbase 3.0. |
static interface |
KeyValue.SamePrefixComparator<T>
Avoids redundant comparisons for better performance.
|
static class |
KeyValue.Type
Key type.
|
Modifier and Type | Field and Description |
---|---|
protected byte[] |
bytes |
static byte[] |
COLUMN_FAMILY_DELIM_ARRAY |
static char |
COLUMN_FAMILY_DELIMITER
Colon character in UTF-8
|
static KeyValue.KVComparator |
COMPARATOR
Deprecated.
Use
CellComparator.getInstance() instead. Deprecated for hbase 2.0, remove
for hbase 3.0. |
static int |
FAMILY_LENGTH_SIZE
Size of the family length field in bytes
|
static int |
FIXED_OVERHEAD |
static int |
KEY_INFRASTRUCTURE_SIZE |
static int |
KEY_LENGTH_SIZE
Size of the key length field in bytes
|
static int |
KEYVALUE_INFRASTRUCTURE_SIZE |
static int |
KEYVALUE_WITH_TAGS_INFRASTRUCTURE_SIZE |
protected int |
length |
private static org.slf4j.Logger |
LOG |
static KeyValue |
LOWESTKEY
Lowest possible key.
|
static KeyValue.KVComparator |
META_COMPARATOR
Deprecated.
Use
MetaCellComparator.META_COMPARATOR instead. Deprecated for hbase 2.0,
remove for hbase 3.0. |
protected int |
offset |
static int |
ROW_KEY_OFFSET |
static int |
ROW_LENGTH_SIZE
Size of the row length field in bytes
|
static int |
ROW_OFFSET |
private long |
seqId |
static int |
TAGS_LENGTH_SIZE
Size of the tags length field in bytes
|
static int |
TIMESTAMP_SIZE
Size of the timestamp field in bytes
|
static int |
TIMESTAMP_TYPE_SIZE |
static int |
TYPE_SIZE
Size of the key type field in bytes
|
CELL_NOT_BASED_ON_CHUNK
MAX_TAGS_LENGTH
Constructor and Description |
---|
KeyValue()
Writable Constructor -- DO NOT USE
|
KeyValue(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.
|
KeyValue(byte[] row,
byte[] family,
byte[] qualifier,
long timestamp,
byte[] value,
List<Tag> tags)
Constructs KeyValue structure filled with specified values.
|
KeyValue(byte[] row,
byte[] family,
byte[] qualifier,
long timestamp,
byte[] value,
Tag[] tags)
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 length
length . |
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 length
length . |
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(Cell c) |
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.
|
Modifier and Type | Method and Description |
---|---|
private int |
calculateHashForKey(Cell cell) |
(package private) static void |
checkParameters(byte[] row,
int rlength,
byte[] family,
int flength,
int qlength,
int vlength)
Checks the parameters passed to a constructor.
|
KeyValue |
clone()
Clones a KeyValue.
|
static KeyValue |
create(DataInput in)
Create a KeyValue reading from
in |
static KeyValue |
create(int length,
DataInput in)
Create a KeyValue reading
length from in |
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.
|
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.
|
KeyValue |
createKeyOnly(boolean lenAsVal)
Creates a new KeyValue that only contains the key portion (the value is set to be null).
|
ExtendedCell |
deepClone()
Does a deep copy of the contents to a new memory area and returns it as a new cell.
|
boolean |
equals(Object other)
Needed doing 'contains' on List.
|
byte[] |
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.
|
static int |
getDelimiter(byte[] b,
int offset,
int length,
int delimiter)
Find index of passed delimiter walking from start of buffer forwards.
|
static int |
getDelimiterInReverse(byte[] b,
int offset,
int length,
int delimiter)
Find index of passed delimiter walking from end of buffer backwards.
|
byte[] |
getFamilyArray()
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)
|
byte |
getFamilyLength()
Returns Family length
|
byte |
getFamilyLength(int famLenPos)
Returns Family length
|
(package private) int |
getFamilyLengthPosition(int rowLength) |
int |
getFamilyOffset()
Returns Family offset
|
(package private) int |
getFamilyOffset(int familyLenPosition)
Returns Family offset
|
byte[] |
getKey()
Do not use unless you have to.
|
static long |
getKeyDataStructureSize(int rlength,
int flength,
int qlength)
Computes the number of bytes that a
KeyValue instance with the provided
characteristics would take up in its underlying data structure for the key. |
int |
getKeyLength()
Returns Length of key portion.
|
int |
getKeyOffset()
Returns Key offset in backing buffer..
|
String |
getKeyString() |
static long |
getKeyValueDataStructureSize(int klength,
int vlength,
int tagsLength)
Computes the number of bytes that a
KeyValue instance with the provided
characteristics would take up for its underlying data structure. |
static long |
getKeyValueDataStructureSize(int rlength,
int flength,
int qlength,
int vlength)
Computes the number of bytes that a
KeyValue instance with the provided
characteristics would take up for its underlying data structure. |
static long |
getKeyValueDataStructureSize(int rlength,
int flength,
int qlength,
int vlength,
int tagsLength)
Computes the number of bytes that a
KeyValue instance with the provided
characteristics would take up for its underlying data structure. |
int |
getLength()
Returns Length of bytes this KeyValue occupies in
getBuffer() . |
private static int |
getLength(byte[] bytes,
int offset)
Determines the total length of the KeyValue stored in the specified byte array and offset.
|
int |
getOffset()
Returns Offset into
getBuffer() at which this KeyValue starts. |
byte[] |
getQualifierArray()
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)
|
int |
getQualifierLength()
Returns Qualifier length
|
private int |
getQualifierLength(int rlength,
int flength)
Returns Qualifier length
|
(package private) int |
getQualifierLength(int keyLength,
int rlength,
int flength)
Returns Qualifier length
|
int |
getQualifierOffset()
Returns Qualifier offset
|
private int |
getQualifierOffset(int foffset)
Returns Qualifier offset
|
(package private) int |
getQualifierOffset(int foffset,
int flength)
Returns Qualifier offset
|
byte[] |
getRowArray()
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)
|
short |
getRowLength()
Returns Row length
|
int |
getRowOffset()
Returns Row offset
|
long |
getSequenceId()
used to achieve atomic operations in the memstore.
|
int |
getSerializedSize()
Returns Serialized size (defaults to include tag length).
|
int |
getSerializedSize(boolean withTags)
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> |
byte[] |
getTagsArray()
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)
|
int |
getTagsLength()
Return the total length of the tag bytes
|
int |
getTagsOffset()
Return the offset where the tag data starts.
|
long |
getTimestamp()
Return the timestamp.
|
(package private) long |
getTimestamp(int keylength)
Return the timestamp.
|
int |
getTimestampOffset()
Returns Timestamp offset
|
private int |
getTimestampOffset(int keylength)
Return the timestamp offset
|
byte |
getTypeByte()
Returns KeyValue.TYPE byte representation
|
(package private) byte |
getTypeByte(int keyLength)
Return the KeyValue.TYPE byte representation
|
byte[] |
getValueArray()
Returns the backing array of the entire KeyValue (all KeyValue fields are in a single array)
|
int |
getValueLength()
Returns Value length
|
int |
getValueOffset()
Returns the value offset
|
int |
hashCode()
In line with
equals(Object) , only uses the key portion, not the value. |
long |
heapSize()
HeapSize implementation
We do not count the bytes in the rowCache because it should be empty for a KeyValue in the
MemStore.
|
static String |
humanReadableTimestamp(long timestamp) |
boolean |
isLatestTimestamp()
Returns True if this KeyValue has a LATEST_TIMESTAMP timestamp.
|
static String |
keyToString(byte[] k)
Return key as a String, empty string if k is null.
|
static String |
keyToString(byte[] b,
int o,
int l)
Use for logging.
|
static long |
oswrite(KeyValue kv,
OutputStream out,
boolean withTags)
Deprecated.
As of release 2.0.0, this will be removed in HBase 3.0.0. Instead use
write(OutputStream, boolean) |
void |
setSequenceId(long seqId)
Sets with the given seqId.
|
void |
setTimestamp(byte[] ts)
Sets with the given timestamp.
|
void |
setTimestamp(long ts)
Sets with the given timestamp.
|
KeyValue |
shallowCopy()
Creates a shallow copy of this KeyValue, reusing the data byte buffer.
|
String |
toString() |
Map<String,Object> |
toStringMap()
Produces a string map for this key/value pair.
|
boolean |
updateLatestStamp(byte[] now)
Update the timestamp.
|
void |
write(ByteBuffer buf,
int offset)
Write this Cell into the given buf's offset in a
KeyValue format. |
static long |
write(KeyValue kv,
DataOutput out)
Write out a KeyValue in the manner in which we used to when KeyValue was a Writable.
|
int |
write(OutputStream out,
boolean withTags)
Write this cell to an OutputStream in a
KeyValue format. |
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.
|
finalize, getClass, notify, notifyAll, wait, wait, wait
getChunkId
checkForTagsLength, cloneTags, createCell, getTag, getTags
private static final org.slf4j.Logger LOG
public static final int FIXED_OVERHEAD
public static final char COLUMN_FAMILY_DELIMITER
public static final byte[] COLUMN_FAMILY_DELIM_ARRAY
@Deprecated public static final KeyValue.KVComparator COMPARATOR
CellComparator.getInstance()
instead. Deprecated for hbase 2.0, remove
for hbase 3.0.@Deprecated public static final KeyValue.KVComparator META_COMPARATOR
MetaCellComparator.META_COMPARATOR
instead. Deprecated for hbase 2.0,
remove for hbase 3.0.public static final int KEY_LENGTH_SIZE
public static final int TYPE_SIZE
public static final int ROW_LENGTH_SIZE
public static final int FAMILY_LENGTH_SIZE
public static final int TIMESTAMP_SIZE
public static final int TIMESTAMP_TYPE_SIZE
public static final int KEY_INFRASTRUCTURE_SIZE
public static final int ROW_OFFSET
public static final int ROW_KEY_OFFSET
public static final int KEYVALUE_INFRASTRUCTURE_SIZE
public static final int TAGS_LENGTH_SIZE
public static final int KEYVALUE_WITH_TAGS_INFRASTRUCTURE_SIZE
public static final KeyValue LOWESTKEY
protected byte[] bytes
protected int offset
protected int length
private long seqId
public KeyValue()
public KeyValue(byte[] bytes)
bytes
content is formatted as a KeyValue blob.bytes
- byte arraypublic KeyValue(byte[] bytes, int offset)
bytes
content starting at offset
is formatted as a KeyValue blob.bytes
- byte arrayoffset
- offset to start of KeyValuepublic KeyValue(byte[] bytes, int offset, int length)
length
.bytes
- byte arrayoffset
- offset to start of the KeyValuelength
- length of the KeyValuepublic KeyValue(byte[] bytes, int offset, int length, long ts)
length
.bytes
- byte arrayoffset
- offset to start of the KeyValuelength
- length of the KeyValuets
- timestamppublic KeyValue(byte[] row, long timestamp)
KeyValue.Type.Maximum
row
- - row key (arbitrary byte array)timestamp
- version timestamppublic KeyValue(byte[] row, long timestamp, KeyValue.Type type)
row
- - row key (arbitrary byte array)timestamp
- version timestamppublic KeyValue(byte[] row, byte[] family, byte[] qualifier)
KeyValue.Type.Maximum
row
- - row key (arbitrary byte array)family
- family namequalifier
- column qualifierpublic KeyValue(byte[] row, byte[] family, byte[] qualifier, byte[] value)
row
- - row key (arbitrary byte array)family
- family namequalifier
- column qualifierpublic KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type)
row
- row keyfamily
- family namequalifier
- column qualifiertimestamp
- version timestamptype
- key typeIllegalArgumentException
- an illegal value was passedpublic KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, byte[] value)
row
- row keyfamily
- family namequalifier
- column qualifiertimestamp
- version timestampvalue
- column valueIllegalArgumentException
- an illegal value was passedpublic KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, byte[] value, Tag[] tags)
row
- row keyfamily
- family namequalifier
- column qualifiertimestamp
- version timestampvalue
- column valuetags
- tagsIllegalArgumentException
- an illegal value was passedpublic KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, byte[] value, List<Tag> tags)
row
- row keyfamily
- family namequalifier
- column qualifiertimestamp
- version timestampvalue
- column valuetags
- tags non-empty list of tags or nullIllegalArgumentException
- an illegal value was passedpublic KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type, byte[] value)
row
- row keyfamily
- family namequalifier
- column qualifiertimestamp
- version timestamptype
- key typevalue
- column valueIllegalArgumentException
- an illegal value was passedpublic KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type, byte[] value, List<Tag> tags)
Column is split into two fields, family and qualifier.
row
- row keyfamily
- family namequalifier
- column qualifiertimestamp
- version timestamptype
- key typevalue
- column valueIllegalArgumentException
- an illegal value was passedpublic KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, KeyValue.Type type, byte[] value, byte[] tags)
row
- row keyfamily
- family namequalifier
- column qualifiertimestamp
- version timestamptype
- key typevalue
- column valueIllegalArgumentException
- an illegal value was passedpublic 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)
row
- row keyfamily
- family namequalifier
- column qualifierqoffset
- qualifier offsetqlength
- qualifier lengthtimestamp
- version timestamptype
- key typevalue
- column valuevoffset
- value offsetvlength
- value lengthIllegalArgumentException
- an illegal value was passedpublic KeyValue(byte[] row, byte[] family, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength, byte[] tags)
row
- row keyfamily
- family namequalifier
- qualifier nameqoffset
- qualifier offsetqlength
- qualifier lengthtimestamp
- version timestamptype
- key typevalue
- column valuevoffset
- value offsetvlength
- value lengthtags
- tagspublic 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)
Column is split into two fields, family and qualifier.
row
- row keyIllegalArgumentException
- an illegal value was passedpublic 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)
Column is split into two fields, family and qualifier.
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 nullIllegalArgumentException
- an illegal value was passed or there is insufficient space
remaining in the bufferpublic 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)
Column is split into two fields, family and qualifier.
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
- tagsIllegalArgumentException
- an illegal value was passedpublic 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)
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 tagspublic KeyValue(int rlength, int flength, int qlength, long timestamp, KeyValue.Type type, int vlength)
Column is split into two fields, family and qualifier.
rlength
- row lengthflength
- family lengthqlength
- qualifier lengthtimestamp
- version timestamptype
- key typevlength
- value lengthIllegalArgumentException
- an illegal value was passedpublic KeyValue(int rlength, int flength, int qlength, long timestamp, KeyValue.Type type, int vlength, int tagsLength)
Column is split into two fields, family and qualifier.
rlength
- row lengthflength
- family lengthqlength
- qualifier lengthtimestamp
- version timestamptype
- key typevlength
- value lengthtagsLength
- length of the tagsIllegalArgumentException
- an illegal value was passedpublic 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)
public static long getKeyValueDataStructureSize(int rlength, int flength, int qlength, int vlength)
KeyValue
instance with the provided
characteristics would take up for its underlying data structure.rlength
- row lengthflength
- family lengthqlength
- qualifier lengthvlength
- value lengthKeyValue
data structure lengthpublic static long getKeyValueDataStructureSize(int rlength, int flength, int qlength, int vlength, int tagsLength)
KeyValue
instance with the provided
characteristics would take up for its underlying data structure.rlength
- row lengthflength
- family lengthqlength
- qualifier lengthvlength
- value lengthtagsLength
- total length of the tagsKeyValue
data structure lengthpublic static long getKeyValueDataStructureSize(int klength, int vlength, int tagsLength)
KeyValue
instance with the provided
characteristics would take up for its underlying data structure.klength
- key lengthvlength
- value lengthtagsLength
- total length of the tagsKeyValue
data structure lengthpublic static long getKeyDataStructureSize(int rlength, int flength, int qlength)
KeyValue
instance with the provided
characteristics would take up in its underlying data structure for the key.rlength
- row lengthflength
- family lengthqlength
- qualifier lengthpublic long getSequenceId()
getSequenceId
in interface Cell
getSequenceId
in interface ExtendedCell
public void setSequenceId(long seqId)
ExtendedCell
setSequenceId
in interface ExtendedCell
seqId
- sequence IDprivate static byte[] createEmptyByteArray(int rlength, int flength, int qlength, long timestamp, KeyValue.Type type, int vlength, int tagsLength)
rlength
- row lengthflength
- family lengthqlength
- qualifier lengthtimestamp
- version timestamptype
- key typevlength
- value lengthstatic void checkParameters(byte[] row, int rlength, byte[] family, int flength, int qlength, int vlength) throws IllegalArgumentException
row
- row keyrlength
- row lengthfamily
- family nameflength
- family lengthqlength
- qualifier lengthvlength
- value lengthIllegalArgumentException
- an illegal value was passedpublic 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)
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 lengthIllegalArgumentException
- an illegal value was passed or there is insufficient space
remaining in the bufferprivate 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)
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 lengthprivate 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)
qualifier
- can be a ByteBuffer or a byte[], or null.value
- can be a ByteBuffer or a byte[], or null.public boolean equals(Object other)
public int hashCode()
equals(Object)
, only uses the key portion, not the value.private int calculateHashForKey(Cell cell)
public KeyValue clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
- if cloning of keyValue is not supportedpublic KeyValue shallowCopy()
public static String keyToString(byte[] k)
public Map<String,Object> toStringMap()
public static String keyToString(byte[] b, int o, int l)
b
- Key portion of a KeyValue.o
- Offset to start of keyl
- Length of key.public static String humanReadableTimestamp(long timestamp)
public byte[] getBuffer()
public int getOffset()
getBuffer()
at which this KeyValue starts.public int getLength()
getBuffer()
.private static int getLength(byte[] bytes, int offset)
bytes
- byte arrayoffset
- offset to start of the KeyValuepublic int getKeyOffset()
public String getKeyString()
public int getKeyLength()
public byte[] getValueArray()
getValueArray
in interface Cell
public int getValueOffset()
getValueOffset
in interface Cell
public int getValueLength()
getValueLength
in interface Cell
public byte[] getRowArray()
getRowArray
in interface Cell
public int getRowOffset()
getRowOffset
in interface Cell
public short getRowLength()
getRowLength
in interface Cell
public byte[] getFamilyArray()
getFamilyArray
in interface Cell
public int getFamilyOffset()
getFamilyOffset
in interface Cell
int getFamilyOffset(int familyLenPosition)
public byte getFamilyLength()
getFamilyLength
in interface Cell
public byte getFamilyLength(int famLenPos)
int getFamilyLengthPosition(int rowLength)
public byte[] getQualifierArray()
getQualifierArray
in interface Cell
public int getQualifierOffset()
getQualifierOffset
in interface Cell
private int getQualifierOffset(int foffset)
int getQualifierOffset(int foffset, int flength)
public int getQualifierLength()
getQualifierLength
in interface Cell
private int getQualifierLength(int rlength, int flength)
int getQualifierLength(int keyLength, int rlength, int flength)
public int getTimestampOffset()
private int getTimestampOffset(int keylength)
public boolean isLatestTimestamp()
public boolean updateLatestStamp(byte[] now)
now
- Time to set into this
IFF timestamp ==
HConstants.LATEST_TIMESTAMP
(else, its a noop).public void setTimestamp(long ts)
ExtendedCell
setTimestamp
in interface ExtendedCell
ts
- timestamppublic void setTimestamp(byte[] ts)
ExtendedCell
setTimestamp
in interface ExtendedCell
ts
- buffer containing the timestamp valuepublic byte[] getKey()
getRowArray()
, getFamilyArray()
, getQualifierArray()
, and
getValueArray()
if accessing a KeyValue client-side.public long getTimestamp()
getTimestamp
in interface Cell
long getTimestamp(int keylength)
public byte getTypeByte()
getTypeByte
in interface Cell
getTypeByte
in interface ExtendedCell
byte getTypeByte(int keyLength)
public int getTagsOffset()
getTagsOffset
in interface Cell
getTagsOffset
in interface ExtendedCell
public int getTagsLength()
getTagsLength
in interface Cell
getTagsLength
in interface ExtendedCell
public byte[] getTagsArray()
getTagsArray
in interface Cell
getTagsArray
in interface ExtendedCell
public KeyValue createKeyOnly(boolean lenAsVal)
lenAsVal
- replace value with the actual value length (false=empty)public static int getDelimiter(byte[] b, int offset, int length, int delimiter)
b
- the kv serialized byte[] to processdelimiter
- input delimeter to fetch index from startb
moving rightward.public static int getDelimiterInReverse(byte[] b, int offset, int length, int delimiter)
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 endpublic static KeyValue create(DataInput in) throws IOException
in
in
- Where to read bytes from. Creates a byte array to hold the KeyValue backing bytes
copied from the steam.in
OR if we find a length of zero,
we will return null which can be useful marking a stream as done.IOException
- if any IO error happenpublic static KeyValue create(int length, DataInput in) throws IOException
length
from in
length
- length of the Keyin
- Input to read fromIOException
- if any IO error happenpublic static long write(KeyValue kv, DataOutput out) throws IOException
kv
- the KeyValue on which write is being requestedout
- OutputStream to write keyValue toIOException
- if any IO error happenfor the inverse function
@Deprecated public static long oswrite(KeyValue kv, OutputStream out, boolean withTags) throws IOException
write(OutputStream, boolean)
DataOutput
, just take plain OutputStream
Named oswrite
so does not clash with write(KeyValue, DataOutput)
kv
- the KeyValue on which write is being requestedout
- OutputStream to write keyValue towithTags
- boolean value indicating write is with Tags or notIOException
- if any IO error happenfor the inverse function
,
write(KeyValue, DataOutput)
,
KeyValueUtil.oswrite(Cell, OutputStream, boolean)
public int write(OutputStream out, boolean withTags) throws IOException
ExtendedCell
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>
write
in interface ExtendedCell
out
- Stream to which cell has to be writtenwithTags
- Whether to write tags.IOException
public int getSerializedSize(boolean withTags)
ExtendedCell
<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>
getSerializedSize
in interface ExtendedCell
withTags
- Whether to write tags.KeyValue
format.public int getSerializedSize()
ExtendedCell
getSerializedSize
in interface Cell
getSerializedSize
in interface ExtendedCell
public void write(ByteBuffer buf, int offset)
ExtendedCell
KeyValue
format.write
in interface ExtendedCell
buf
- The buffer where to write the Cell.offset
- The offset within buffer, to write the Cell.public long heapSize()
public ExtendedCell deepClone()
ExtendedCell
deepClone
in interface ExtendedCell
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.