|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.hadoop.hbase.KeyValue
public class KeyValue
An HBase Key/Value.
If being used client-side, the primary methods to access individual fields
are getRow()
, getFamily()
, getQualifier()
,
getTimestamp()
, and getValue()
. These methods allocate new
byte arrays and return copies so they should be avoided server-side.
Instances of this class are immutable. They are not
comparable but Comparators are provided. Comparators change with context,
whether user table or a catalog table comparison context. Its
important that you use the appropriate comparator comparing rows in
particular. There are Comparators for KeyValue instances and then for
just the Key portion of a KeyValue used mostly in HFile
.
KeyValue wraps a byte array and has offset and length for passed array
at where to start interpreting the content as a KeyValue blob. The KeyValue
blob format inside the byte array is:
<keylength> <valuelength> <key> <value>
Key is decomposed as:
<rowlength> <row> <columnfamilylength> <columnfamily> <columnqualifier> <timestamp> <keytype>
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.
TODO: Group Key-only comparators and operations into a Key class, just for neatness sake, if can figure what to call it.
Nested Class Summary | |
---|---|
static class |
KeyValue.KeyComparator
Compare key portion of a KeyValue . |
static class |
KeyValue.KVComparator
Compare KeyValues. |
static class |
KeyValue.MetaComparator
A KeyValue.KVComparator for .META. catalog table
KeyValue s. |
static class |
KeyValue.MetaKeyComparator
Compare key portion of a KeyValue for keys in .META.
table. |
static class |
KeyValue.RootComparator
A KeyValue.KVComparator for -ROOT- catalog table
KeyValue s. |
static class |
KeyValue.RootKeyComparator
Compare key portion of a KeyValue for keys in -ROOT- |
static class |
KeyValue.RowComparator
Comparator that compares row component only of a KeyValue. |
static class |
KeyValue.SplitKeyValue
Utility class that splits a KeyValue buffer into separate byte arrays. |
static class |
KeyValue.Type
Key type. |
Field Summary | |
---|---|
static byte[] |
COLUMN_FAMILY_DELIM_ARRAY
|
static char |
COLUMN_FAMILY_DELIMITER
Colon character in UTF-8 |
static KeyValue.KVComparator |
COMPARATOR
Comparator for plain key/values; i.e. |
static KeyValue.KeyComparator |
KEY_COMPARATOR
Comparator for plain key; i.e. |
static int |
KEY_INFRASTRUCTURE_SIZE
|
static int |
KEYVALUE_INFRASTRUCTURE_SIZE
|
static KeyValue |
LOWESTKEY
Lowest possible key. |
static KeyValue.KVComparator |
META_COMPARATOR
A KeyValue.KVComparator for .META. catalog table
KeyValue s. |
static KeyValue.KeyComparator |
META_KEY_COMPARATOR
A KeyValue.KVComparator for .META. catalog table
KeyValue keys. |
static KeyValue.KVComparator |
ROOT_COMPARATOR
A KeyValue.KVComparator for -ROOT- catalog table
KeyValue s. |
static KeyValue.KeyComparator |
ROOT_KEY_COMPARATOR
A KeyValue.KVComparator for -ROOT- catalog table
KeyValue keys. |
static int |
ROW_OFFSET
|
static int |
TIMESTAMP_TYPE_SIZE
|
Constructor Summary | |
---|---|
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 filled with null value. |
|
KeyValue(byte[] row,
byte[] family,
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,
byte[] family,
byte[] qualifier,
long timestamp,
byte[] value)
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[] bytes,
int offset)
Creates a KeyValue from the specified byte array and offset. |
|
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,
long timestamp)
Constructs KeyValue structure filled with null value. |
|
KeyValue(byte[] row,
long timestamp,
KeyValue.Type type)
Constructs KeyValue structure filled with null value. |
Method Summary | |
---|---|
KeyValue |
clone()
Clones a KeyValue. |
void |
convertToKeyOnly(boolean lenAsVal)
Converts this KeyValue to only contain the key portion (the value is changed to be null). |
static KeyValue |
createFirstOnRow(byte[] row)
Create a KeyValue that is smaller than all other possible KeyValues for the given row. |
static KeyValue |
createFirstOnRow(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 KeyValue |
createFirstOnRow(byte[] row,
byte[] f,
byte[] q,
long ts)
|
static KeyValue |
createFirstOnRow(byte[] row,
byte[] c,
long ts)
Deprecated. |
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. |
static KeyValue |
createFirstOnRow(byte[] row,
long ts)
Creates a KeyValue that is smaller than all other KeyValues that are older than the passed timestamp. |
static KeyValue |
createKeyValueFromKey(byte[] b)
|
static KeyValue |
createKeyValueFromKey(byte[] b,
int o,
int l)
|
static KeyValue |
createKeyValueFromKey(ByteBuffer bb)
|
static KeyValue |
createLastOnRow(byte[] row)
Creates a KeyValue that is last on the specified row id. |
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. |
boolean |
equals(Object other)
|
byte[] |
getBuffer()
|
static int |
getDelimiter(byte[] b,
int offset,
int length,
int delimiter)
|
static int |
getDelimiterInReverse(byte[] b,
int offset,
int length,
int delimiter)
Find index of passed delimiter walking from end of buffer backwards. |
byte[] |
getFamily()
Primarily for use client-side. |
static int |
getFamilyDelimiterIndex(byte[] b,
int offset,
int length)
|
byte |
getFamilyLength()
|
byte |
getFamilyLength(int foffset)
|
int |
getFamilyOffset()
|
int |
getFamilyOffset(int rlength)
|
byte[] |
getKey()
Do not use unless you have to. |
int |
getKeyLength()
|
int |
getKeyOffset()
|
String |
getKeyString()
|
int |
getLength()
|
long |
getMemstoreTS()
Here be dragons |
int |
getOffset()
|
byte[] |
getQualifier()
Primarily for use client-side. |
int |
getQualifierLength()
|
int |
getQualifierLength(int rlength,
int flength)
|
int |
getQualifierOffset()
|
int |
getQualifierOffset(int foffset)
|
byte[] |
getRow()
Primarily for use client-side. |
static KeyValue.KeyComparator |
getRowComparator(byte[] tableName)
Get the appropriate row comparator for the specified table. |
short |
getRowLength()
|
int |
getRowOffset()
|
long |
getTimestamp()
|
int |
getTimestampOffset()
|
int |
getTimestampOffset(int keylength)
|
int |
getTotalColumnLength()
|
int |
getTotalColumnLength(int rlength,
int foffset)
|
byte |
getType()
|
byte[] |
getValue()
Returns value in a new byte array. |
int |
getValueLength()
|
int |
getValueOffset()
|
int |
hashCode()
|
long |
heapSize()
|
boolean |
isDelete()
|
boolean |
isDeleteColumnOrFamily()
|
boolean |
isDeleteFamily()
|
boolean |
isDeleteType()
|
boolean |
isEmptyColumn()
|
boolean |
isLatestTimestamp()
|
static String |
keyToString(byte[] k)
|
static String |
keyToString(byte[] b,
int o,
int l)
|
static byte[] |
makeColumn(byte[] family,
byte[] qualifier)
Makes a column in family:qualifier form from separate byte arrays. |
boolean |
matchingColumn(byte[] family,
byte[] qualifier)
|
boolean |
matchingColumnNoDelimiter(byte[] column)
|
boolean |
matchingFamily(byte[] family)
|
boolean |
matchingFamily(byte[] family,
int offset,
int length)
|
boolean |
matchingFamily(KeyValue other)
|
boolean |
matchingQualifier(byte[] qualifier)
|
boolean |
matchingQualifier(byte[] qualifier,
int offset,
int length)
|
boolean |
matchingQualifier(KeyValue other)
|
boolean |
matchingRow(byte[] row)
|
boolean |
matchingRow(byte[] row,
int offset,
int length)
|
boolean |
matchingRow(KeyValue other)
|
boolean |
nonNullRowAndColumn()
|
static byte[][] |
parseColumn(byte[] c)
Splits a column in family:qualifier form into separate byte arrays. |
void |
readFields(DataInput in)
|
void |
readFields(int length,
DataInput in)
|
void |
setMemstoreTS(long memstoreTS)
|
KeyValue.SplitKeyValue |
split()
|
String |
toString()
|
Map<String,Object> |
toStringMap()
Produces a string map for this key/value pair. |
boolean |
updateLatestStamp(byte[] now)
|
void |
write(DataOutput out)
|
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final char COLUMN_FAMILY_DELIMITER
public static final byte[] COLUMN_FAMILY_DELIM_ARRAY
public static KeyValue.KVComparator COMPARATOR
public static KeyValue.KeyComparator KEY_COMPARATOR
public static KeyValue.KVComparator META_COMPARATOR
KeyValue.KVComparator
for .META.
catalog table
KeyValue
s.
public static KeyValue.KeyComparator META_KEY_COMPARATOR
KeyValue.KVComparator
for .META.
catalog table
KeyValue
keys.
public static KeyValue.KVComparator ROOT_COMPARATOR
KeyValue.KVComparator
for -ROOT-
catalog table
KeyValue
s.
public static KeyValue.KeyComparator ROOT_KEY_COMPARATOR
KeyValue.KVComparator
for -ROOT-
catalog table
KeyValue
keys.
public static final int TIMESTAMP_TYPE_SIZE
public static final int KEY_INFRASTRUCTURE_SIZE
public static final int ROW_OFFSET
public static final int KEYVALUE_INFRASTRUCTURE_SIZE
public static final KeyValue LOWESTKEY
Constructor Detail |
---|
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[] row, long timestamp)
KeyValue.Type.Maximum
row
- - row key (arbitrary byte array)timestamp
- public KeyValue(byte[] row, long timestamp, KeyValue.Type type)
row
- - row key (arbitrary byte array)timestamp
- public 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 type
IllegalArgumentException
public KeyValue(byte[] row, byte[] family, byte[] qualifier, long timestamp, byte[] value)
row
- row keyfamily
- family namequalifier
- column qualifiertimestamp
- version timestampvalue
- column value
IllegalArgumentException
public 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 value
IllegalArgumentException
public KeyValue(byte[] row, byte[] family, byte[] qualifier, int qoffset, int qlength, long timestamp, KeyValue.Type type, byte[] value, int voffset, int vlength)
row
- row keyfamily
- family namequalifier
- column qualifierqoffset
- qualifier offsetqlength
- qualifier lengthtimestamp
- version timestamptype
- key typevalue
- column valuevoffset
- value offsetvlength
- value length
IllegalArgumentException
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)
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 length
IllegalArgumentException
Method Detail |
---|
public static KeyValue.KeyComparator getRowComparator(byte[] tableName)
tableName
- The table name.
public long getMemstoreTS()
public void setMemstoreTS(long memstoreTS)
public boolean equals(Object other)
equals
in class Object
public int hashCode()
hashCode
in class Object
public KeyValue clone()
clone
in class Object
public String toString()
toString
in class Object
public static String keyToString(byte[] k)
k
- Key portion of a KeyValue.
public Map<String,Object> toStringMap()
public static String keyToString(byte[] b, int o, int l)
public byte[] getBuffer()
public int getOffset()
getBuffer()
at which this KeyValue starts.public int getLength()
getBuffer()
.public int getKeyOffset()
public String getKeyString()
public int getKeyLength()
public int getValueOffset()
public int getValueLength()
public int getRowOffset()
public short getRowLength()
public int getFamilyOffset()
public int getFamilyOffset(int rlength)
public byte getFamilyLength()
public byte getFamilyLength(int foffset)
public int getQualifierOffset()
public int getQualifierOffset(int foffset)
public int getQualifierLength()
public int getQualifierLength(int rlength, int flength)
public int getTotalColumnLength()
public int getTotalColumnLength(int rlength, int foffset)
public int getTimestampOffset()
public int getTimestampOffset(int keylength)
keylength
- Pass if you have it to save on a int creation.
public boolean isLatestTimestamp()
public boolean updateLatestStamp(byte[] now)
now
- Time to set into this
IFF timestamp ==
HConstants.LATEST_TIMESTAMP
(else, its a noop).
public byte[] getKey()
getRow()
, getFamily()
, getQualifier()
, and
getValue()
if accessing a KeyValue client-side.
public byte[] getValue()
getBuffer()
with appropriate offsets and lengths instead to
save on allocations.
public byte[] getRow()
If server-side, use getBuffer()
with appropriate offsets and
lengths instead.
public long getTimestamp()
public byte getType()
public boolean isDelete()
KeyValue.Type.Delete
or
a {KeyValue.Type#DeleteFamily} or a KeyValue.Type.DeleteColumn
KeyValue type.public boolean isDeleteType()
KeyValue.Type.Delete
type.public boolean isDeleteFamily()
public boolean isDeleteColumnOrFamily()
public byte[] getFamily()
If server-side, use getBuffer()
with appropriate offsets and
lengths instead.
public byte[] getQualifier()
If server-side, use getBuffer()
with appropriate offsets and
lengths instead.
Use getBuffer()
with appropriate offsets and lengths instead.
public KeyValue.SplitKeyValue split()
public boolean matchingFamily(byte[] family)
family
-
public boolean matchingFamily(byte[] family, int offset, int length)
public boolean matchingFamily(KeyValue other)
public boolean matchingQualifier(byte[] qualifier)
qualifier
-
public boolean matchingQualifier(byte[] qualifier, int offset, int length)
public boolean matchingQualifier(KeyValue other)
public boolean matchingRow(byte[] row)
public boolean matchingRow(byte[] row, int offset, int length)
public boolean matchingRow(KeyValue other)
public boolean matchingColumnNoDelimiter(byte[] column)
column
- Column minus its delimiter
public boolean matchingColumn(byte[] family, byte[] qualifier)
family
- column familyqualifier
- column qualifier
public boolean nonNullRowAndColumn()
public boolean isEmptyColumn()
public void convertToKeyOnly(boolean lenAsVal)
This method is used by KeyOnlyFilter
and is an advanced feature of
KeyValue, proceed with caution.
lenAsVal
- replace value with the actual value length (false=empty)public static byte[][] parseColumn(byte[] c)
Not recommend to be used as this is old-style API.
c
- The column.
public static byte[] makeColumn(byte[] family, byte[] qualifier)
Not recommended for usage as this is old-style API.
family
- qualifier
-
public static int getFamilyDelimiterIndex(byte[] b, int offset, int length)
b
-
public static int getDelimiter(byte[] b, int offset, int length, int delimiter)
b
- delimiter
-
b
moving rightward.public static int getDelimiterInReverse(byte[] b, int offset, int length, int delimiter)
b
- delimiter
-
public static KeyValue createLastOnRow(byte[] row)
row
- row key
row
public static KeyValue createFirstOnRow(byte[] row)
row
- - row key (arbitrary byte array)
row
public static KeyValue createFirstOnRow(byte[] row, long ts)
row
- - row key (arbitrary byte array)ts
- - timestamp
row
and timestamp.public static KeyValue createFirstOnRow(byte[] row, byte[] c, long ts)
row
- - row key (arbitrary byte array)c
- column - parseColumn(byte[])
is called to split
the column.ts
- - timestamp
row
, column and timestamppublic static KeyValue createFirstOnRow(byte[] row, byte[] family, byte[] qualifier)
row
- - row key (arbitrary byte array)family
- - family namequalifier
- - column qualifier
row
, and column.public static KeyValue createFirstOnRow(byte[] row, byte[] f, byte[] q, long ts)
row
- - row key (arbitrary byte array)f
- - family nameq
- - column qualifierts
- - timestamp
row
, column and timestamppublic static KeyValue createFirstOnRow(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength)
row
- row keyroffset
- row offsetrlength
- row lengthfamily
- family namefoffset
- family offsetflength
- family lengthqualifier
- column qualifierqoffset
- qualifier offsetqlength
- qualifier length
public static KeyValue createLastOnRow(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength)
row
- row keyroffset
- row offsetrlength
- row lengthfamily
- family namefoffset
- family offsetflength
- family lengthqualifier
- column qualifierqoffset
- qualifier offsetqlength
- qualifier length
public static KeyValue createKeyValueFromKey(byte[] b)
b
-
public static KeyValue createKeyValueFromKey(ByteBuffer bb)
bb
-
public static KeyValue createKeyValueFromKey(byte[] b, int o, int l)
b
- o
- l
-
public long heapSize()
heapSize
in interface HeapSize
public void readFields(int length, DataInput in) throws IOException
IOException
public void readFields(DataInput in) throws IOException
readFields
in interface org.apache.hadoop.io.Writable
IOException
public void write(DataOutput out) throws IOException
write
in interface org.apache.hadoop.io.Writable
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |