org.apache.hadoop.hbase
Class KeyValue

java.lang.Object
  extended by org.apache.hadoop.hbase.KeyValue
All Implemented Interfaces:
Cloneable, Cell, HeapSize

@InterfaceAudience.Public
@InterfaceStability.Evolving
public class KeyValue
extends Object
implements Cell, HeapSize, Cloneable

An HBase Key/Value. This is the fundamental HBase Type.

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. 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 KeyValue instances and then for just the Key portion of a KeyValue used mostly by HFile.

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


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 KeyValues.
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 KeyValues.
static class KeyValue.RootKeyComparator
          Compare key portion of a KeyValue for keys in -ROOT- table.
static class KeyValue.RowComparator
          Comparator that compares row component only of a KeyValue.
static interface KeyValue.SamePrefixComparator<T>
          Avoids redundant comparisons for better performance.
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 int FAMILY_LENGTH_SIZE
          Size of the family length field in bytes
static KeyValue.KeyComparator KEY_COMPARATOR
          Comparator for plain key; i.e.
static int KEY_INFRASTRUCTURE_SIZE
           
static int KEY_LENGTH_SIZE
          Size of the key length field in bytes
static int KEYVALUE_INFRASTRUCTURE_SIZE
           
static KeyValue LOWESTKEY
          Lowest possible key.
static KeyValue.KVComparator META_COMPARATOR
          A KeyValue.KVComparator for .META. catalog table KeyValues.
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 KeyValues.
static KeyValue.KeyComparator ROOT_KEY_COMPARATOR
          A KeyValue.KVComparator for -ROOT- catalog table KeyValue keys.
static int ROW_LENGTH_SIZE
          Size of the row length field in bytes
static int ROW_OFFSET
           
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
 
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[] buffer, 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[] 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)
          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[] bytes, int offset, int length, int keyLength)
          Creates a KeyValue from the specified byte array, starting at offset, for length length, and a known keyLength.
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.
 
Method Summary
 KeyValue clone()
          Clones a KeyValue.
static KeyValue create(DataInput in)
           
static KeyValue create(int length, DataInput in)
          Create a KeyValue reading length from in
static KeyValue createFirstDeleteFamilyOnRow(byte[] row, byte[] family)
          Create a Delete Family KeyValue for the specified row and family that would be smaller than all other possible Delete Family KeyValues that have the same row and family.
static 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[] buffer, byte[] row, byte[] family, byte[] qualifier)
          Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier.
static KeyValue createFirstOnRow(byte[] row, byte[] f, byte[] q, long ts)
           
static KeyValue createFirstOnRow(byte[] buffer, int boffset, byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength)
          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, 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, int roffset, short rlength)
          Create a KeyValue that is smaller than all other possible KeyValues for the given row.
static KeyValue createFirstOnRow(byte[] row, long ts)
          Creates a KeyValue that is smaller than all other KeyValues that are older than the passed timestamp.
 KeyValue createFirstOnRowColTS(long ts)
          Creates the first KV with the row/family/qualifier of this KV and the given timestamp.
 KeyValue createKeyOnly(boolean lenAsVal)
          Creates a new KeyValue that only contains the key portion (the value is set to be null).
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.
 KeyValue createLastOnRowCol()
          Similar to createLastOnRow(byte[], int, int, byte[], int, int, byte[], int, int) but creates the last key on the row/column of this KV (the value part of the returned KV is always empty).
 boolean equals(Object other)
          Needed doing 'contains' on List.
 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.
 byte[] getFamilyArray()
          Contiguous bytes composed of legal HDFS filename characters which may start at any index in the containing array.
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.
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()
           
 int getKeyOffset()
           
 String getKeyString()
           
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.
 int getLength()
           
 long getMemstoreTS()
          Deprecated. 
 long getMvccVersion()
          Here be dragons
 int getOffset()
           
 byte[] getQualifier()
          Primarily for use client-side.
 byte[] getQualifierArray()
          Contiguous raw bytes that may start at any index in the containing array.
 int getQualifierLength()
           
 int getQualifierLength(int rlength, int flength)
           
 int getQualifierOffset()
           
 int getQualifierOffset(int foffset)
           
 byte[] getRow()
          Primarily for use client-side.
 byte[] getRowArray()
          Contiguous raw bytes that may start at any index in the containing array.
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 getTypeByte()
           
 byte[] getValue()
          Returns value in a new byte array.
 byte[] getValueArray()
          Contiguous raw bytes that may start at any index in the containing array.
 ByteBuffer getValueAsByteBuffer()
          Returns the value wrapped in a new ByteBuffer.
 int getValueLength()
           
 int getValueOffset()
           
 int hashCode()
           
 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)
           
static KeyValue iscreate(InputStream in)
          Create a KeyValue reading from the raw InputStream.
 boolean isDelete()
           
static boolean isDelete(byte t)
           
 boolean isDeleteColumnOrFamily()
           
 boolean isDeleteFamily()
           
 boolean isDeleteType()
           
 boolean isEmptyColumn()
           
 boolean isInternal()
           
 boolean isLatestTimestamp()
           
static String keyToString(byte[] k)
           
static String keyToString(byte[] b, int o, int l)
           
 void loadValue(ByteBuffer dst)
          Loads this object's value into the provided ByteBuffer.
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 matchingColumn(byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength)
          Checks if column matches.
 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 long oswrite(KeyValue kv, OutputStream out)
          Write out a KeyValue in the manner in which we used to when KeyValue was a Writable but do not require a DataOutput, just take plain OutputStream Named oswrite so does not clash with write(KeyValue, DataOutput)
static byte[][] parseColumn(byte[] c)
          Splits a column in family:qualifier form into separate byte arrays.
 void setMemstoreTS(long memstoreTS)
          Deprecated. 
 void setMvccVersion(long mvccVersion)
           
 KeyValue shallowCopy()
          Creates a shallow copy of this KeyValue, reusing the data byte buffer.
 KeyValue.SplitKeyValue split()
           
 String toString()
           
 Map<String,Object> toStringMap()
          Produces a string map for this key/value pair.
 boolean updateLatestStamp(byte[] now)
           
static long write(KeyValue kv, DataOutput out)
          Write out a KeyValue in the manner in which we used to when KeyValue was a Writable.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

COLUMN_FAMILY_DELIMITER

public static final char COLUMN_FAMILY_DELIMITER
Colon character in UTF-8

See Also:
Constant Field Values

COLUMN_FAMILY_DELIM_ARRAY

public static final byte[] COLUMN_FAMILY_DELIM_ARRAY

COMPARATOR

public static final KeyValue.KVComparator COMPARATOR
Comparator for plain key/values; i.e. non-catalog table key/values.


KEY_COMPARATOR

public static final KeyValue.KeyComparator KEY_COMPARATOR
Comparator for plain key; i.e. non-catalog table key. Works on Key portion of KeyValue only.


META_COMPARATOR

public static final KeyValue.KVComparator META_COMPARATOR
A KeyValue.KVComparator for .META. catalog table KeyValues.


META_KEY_COMPARATOR

public static final KeyValue.KeyComparator META_KEY_COMPARATOR
A KeyValue.KVComparator for .META. catalog table KeyValue keys.


ROOT_COMPARATOR

public static final KeyValue.KVComparator ROOT_COMPARATOR
A KeyValue.KVComparator for -ROOT- catalog table KeyValues.


ROOT_KEY_COMPARATOR

public static final KeyValue.KeyComparator ROOT_KEY_COMPARATOR
A KeyValue.KVComparator for -ROOT- catalog table KeyValue keys.


KEY_LENGTH_SIZE

public static final int KEY_LENGTH_SIZE
Size of the key length field in bytes

See Also:
Constant Field Values

TYPE_SIZE

public static final int TYPE_SIZE
Size of the key type field in bytes

See Also:
Constant Field Values

ROW_LENGTH_SIZE

public static final int ROW_LENGTH_SIZE
Size of the row length field in bytes

See Also:
Constant Field Values

FAMILY_LENGTH_SIZE

public static final int FAMILY_LENGTH_SIZE
Size of the family length field in bytes

See Also:
Constant Field Values

TIMESTAMP_SIZE

public static final int TIMESTAMP_SIZE
Size of the timestamp field in bytes

See Also:
Constant Field Values

TIMESTAMP_TYPE_SIZE

public static final int TIMESTAMP_TYPE_SIZE
See Also:
Constant Field Values

KEY_INFRASTRUCTURE_SIZE

public static final int KEY_INFRASTRUCTURE_SIZE
See Also:
Constant Field Values

ROW_OFFSET

public static final int ROW_OFFSET
See Also:
Constant Field Values

KEYVALUE_INFRASTRUCTURE_SIZE

public static final int KEYVALUE_INFRASTRUCTURE_SIZE
See Also:
Constant Field Values

LOWESTKEY

public static final KeyValue 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.

Constructor Detail

KeyValue

public KeyValue()
Writable Constructor -- DO NOT USE


KeyValue

public KeyValue(byte[] bytes)
Creates a KeyValue from the start of the specified byte array. Presumes bytes content is formatted as a KeyValue blob.

Parameters:
bytes - byte array

KeyValue

public KeyValue(byte[] bytes,
                int offset)
Creates a KeyValue from the specified byte array and offset. Presumes bytes content starting at offset is formatted as a KeyValue blob.

Parameters:
bytes - byte array
offset - offset to start of KeyValue

KeyValue

public KeyValue(byte[] bytes,
                int offset,
                int length)
Creates a KeyValue from the specified byte array, starting at offset, and for length length.

Parameters:
bytes - byte array
offset - offset to start of the KeyValue
length - length of the KeyValue

KeyValue

public KeyValue(byte[] bytes,
                int offset,
                int length,
                int keyLength)
Creates a KeyValue from the specified byte array, starting at offset, for length length, and a known keyLength.

Parameters:
bytes - byte array
offset - offset to start of the KeyValue
length - length of the KeyValue
keyLength - length of the key portion of the KeyValue

KeyValue

public KeyValue(byte[] row,
                long timestamp)
Constructs KeyValue structure filled with null value. Sets type to KeyValue.Type.Maximum

Parameters:
row - - row key (arbitrary byte array)
timestamp -

KeyValue

public KeyValue(byte[] row,
                long timestamp,
                KeyValue.Type type)
Constructs KeyValue structure filled with null value.

Parameters:
row - - row key (arbitrary byte array)
timestamp -

KeyValue

public KeyValue(byte[] row,
                byte[] family,
                byte[] qualifier)
Constructs KeyValue structure filled with null value. Sets type to KeyValue.Type.Maximum

Parameters:
row - - row key (arbitrary byte array)
family - family name
qualifier - column qualifier

KeyValue

public KeyValue(byte[] row,
                byte[] family,
                byte[] qualifier,
                byte[] value)
Constructs KeyValue structure filled with null value.

Parameters:
row - - row key (arbitrary byte array)
family - family name
qualifier - column qualifier

KeyValue

public KeyValue(byte[] row,
                byte[] family,
                byte[] qualifier,
                long timestamp,
                KeyValue.Type type)
Constructs KeyValue structure filled with specified values.

Parameters:
row - row key
family - family name
qualifier - column qualifier
timestamp - version timestamp
type - key type
Throws:
IllegalArgumentException

KeyValue

public KeyValue(byte[] row,
                byte[] family,
                byte[] qualifier,
                long timestamp,
                byte[] value)
Constructs KeyValue structure filled with specified values.

Parameters:
row - row key
family - family name
qualifier - column qualifier
timestamp - version timestamp
value - column value
Throws:
IllegalArgumentException

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 key
family - family name
qualifier - column qualifier
timestamp - version timestamp
type - key type
value - column value
Throws:
IllegalArgumentException

KeyValue

public 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.

Parameters:
row - row key
family - family name
qualifier - column qualifier
qoffset - qualifier offset
qlength - qualifier length
timestamp - version timestamp
type - key type
value - column value
voffset - value offset
vlength - value length
Throws:
IllegalArgumentException

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
roffset - row offset
rlength - row length
family - family name
foffset - family offset
flength - family length
qualifier - column qualifier
qoffset - qualifier offset
qlength - qualifier length
timestamp - version timestamp
type - key type
value - column value
voffset - value offset
vlength - value length
Throws:
IllegalArgumentException

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 length
flength - family length
qlength - qualifier length
timestamp - version timestamp
type - key type
vlength - value length
Throws:
IllegalArgumentException

KeyValue

public KeyValue(byte[] buffer,
                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. Uses the provided buffer as its backing data buffer.

Column is split into two fields, family and qualifier.

Parameters:
buffer - the bytes buffer to use
row - row key
roffset - row offset
rlength - row length
family - family name
foffset - family offset
flength - family length
qualifier - column qualifier
qoffset - qualifier offset
qlength - qualifier length
timestamp - version timestamp
type - key type
value - column value
voffset - value offset
vlength - value length
Throws:
IllegalArgumentException - an illegal value was passed or there is insufficient space remaining in the buffer

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)
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 use
boffset - buffer offset
row - row key
roffset - row offset
rlength - row length
family - family name
foffset - family offset
flength - family length
qualifier - column qualifier
qoffset - qualifier offset
qlength - qualifier length
timestamp - version timestamp
type - key type
value - column value
voffset - value offset
vlength - value length
Throws:
IllegalArgumentException - an illegal value was passed or there is insufficient space remaining in the buffer
Method Detail

getRowComparator

public static KeyValue.KeyComparator getRowComparator(byte[] tableName)
Get the appropriate row comparator for the specified table. Hopefully we can get rid of this, I added this here because it's replacing something in HSK. We should move completely off of that.

Parameters:
tableName - The table name.
Returns:
The comparator.

getKeyValueDataStructureSize

public 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.

Parameters:
rlength - row length
flength - family length
qlength - qualifier length
vlength - value length
Returns:
the KeyValue data structure length

getKeyDataStructureSize

public 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.

Parameters:
rlength - row length
flength - family length
qlength - qualifier length
Returns:
the key data structure length

isDelete

public static boolean isDelete(byte t)
Returns:
True if a delete type, a KeyValue.Type.Delete or a {KeyValue.Type#DeleteFamily} or a KeyValue.Type.DeleteColumn KeyValue type.

getMvccVersion

public long getMvccVersion()
Here be dragons

Specified by:
getMvccVersion in interface Cell
Returns:
mvccVersion (always >= 0 if exists), or 0 if it no longer exists

setMvccVersion

public void setMvccVersion(long mvccVersion)

getMemstoreTS

@Deprecated
public long getMemstoreTS()
Deprecated. 


setMemstoreTS

@Deprecated
public void setMemstoreTS(long memstoreTS)
Deprecated. 


equals

public boolean equals(Object other)
Needed doing 'contains' on List. Only compares the key portion, not the value.

Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

clone

public KeyValue clone()
               throws CloneNotSupportedException
Clones a KeyValue. This creates a copy, re-allocating the buffer.

Overrides:
clone in class Object
Returns:
Fully copied clone of this KeyValue
Throws:
CloneNotSupportedException

shallowCopy

public KeyValue 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

public String toString()
Overrides:
toString in class Object

keyToString

public static String keyToString(byte[] k)
Parameters:
k - Key portion of a KeyValue.
Returns:
Key as a String.

toStringMap

public Map<String,Object> toStringMap()
Produces a string map for this key/value pair. Useful for programmatic use and manipulation of the data stored in an HLogKey, 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 containing data from this key

keyToString

public static String keyToString(byte[] b,
                                 int o,
                                 int l)

humanReadableTimestamp

public static String humanReadableTimestamp(long timestamp)

getBuffer

public byte[] getBuffer()
Returns:
The byte array backing this KeyValue.

getOffset

public int getOffset()
Returns:
Offset into getBuffer() at which this KeyValue starts.

getLength

public int getLength()
Returns:
Length of bytes this KeyValue occupies in getBuffer().

getKeyOffset

public int getKeyOffset()
Returns:
Key offset in backing buffer..

getKeyString

public String getKeyString()

getKeyLength

public int getKeyLength()

getValueArray

public byte[] getValueArray()
Description copied from interface: Cell
Contiguous raw bytes that may start at any index in the containing array. Max length is Integer.MAX_VALUE which is 2,147,483,648 bytes.

Specified by:
getValueArray in interface Cell
Returns:
the backing array of the entire KeyValue (all KeyValue fields are in a single array)

getValueOffset

public int getValueOffset()
Specified by:
getValueOffset in interface Cell
Returns:
Value offset

getValueLength

public int getValueLength()
Specified by:
getValueLength in interface Cell
Returns:
Value length

getRowArray

public byte[] getRowArray()
Description copied from interface: Cell
Contiguous raw bytes that may start at any index in the containing array. Max length is Short.MAX_VALUE which is 32,767 bytes.

Specified by:
getRowArray in interface Cell
Returns:
the backing array of the entire KeyValue (all KeyValue fields are in a single array)

getRowOffset

public int getRowOffset()
Specified by:
getRowOffset in interface Cell
Returns:
Row offset

getRowLength

public short getRowLength()
Specified by:
getRowLength in interface Cell
Returns:
Row length

getFamilyArray

public byte[] getFamilyArray()
Description copied from interface: Cell
Contiguous bytes composed of legal HDFS filename characters which may start at any index in the containing array. Max length is Byte.MAX_VALUE, which is 127 bytes.

Specified by:
getFamilyArray in interface Cell
Returns:
the backing array of the entire KeyValue (all KeyValue fields are in a single array)

getFamilyOffset

public int getFamilyOffset()
Specified by:
getFamilyOffset in interface Cell
Returns:
Family offset

getFamilyOffset

public int getFamilyOffset(int rlength)
Returns:
Family offset

getFamilyLength

public byte getFamilyLength()
Specified by:
getFamilyLength in interface Cell
Returns:
Family length

getFamilyLength

public byte getFamilyLength(int foffset)
Returns:
Family length

getQualifierArray

public byte[] getQualifierArray()
Description copied from interface: Cell
Contiguous raw bytes that may start at any index in the containing array. Max length is Short.MAX_VALUE which is 32,767 bytes.

Specified by:
getQualifierArray in interface Cell
Returns:
the backing array of the entire KeyValue (all KeyValue fields are in a single array)

getQualifierOffset

public int getQualifierOffset()
Specified by:
getQualifierOffset in interface Cell
Returns:
Qualifier offset

getQualifierOffset

public int getQualifierOffset(int foffset)
Returns:
Qualifier offset

getQualifierLength

public int getQualifierLength()
Specified by:
getQualifierLength in interface Cell
Returns:
Qualifier length

getQualifierLength

public int getQualifierLength(int rlength,
                              int flength)
Returns:
Qualifier length

getTotalColumnLength

public int getTotalColumnLength()
Returns:
Column (family + qualifier) length

getTotalColumnLength

public int getTotalColumnLength(int rlength,
                                int foffset)
Returns:
Column (family + qualifier) length

getTimestampOffset

public int getTimestampOffset()
Returns:
Timestamp offset

getTimestampOffset

public int getTimestampOffset(int keylength)
Parameters:
keylength - Pass if you have it to save on a int creation.
Returns:
Timestamp offset

isLatestTimestamp

public boolean isLatestTimestamp()
Returns:
True if this KeyValue has a LATEST_TIMESTAMP timestamp.

isInternal

public boolean isInternal()
Returns:
True if this is a "fake" KV created for internal seeking purposes, which should not be seen by user code

updateLatestStamp

public boolean updateLatestStamp(byte[] now)
Parameters:
now - Time to set into this IFF timestamp == HConstants.LATEST_TIMESTAMP (else, its a noop).
Returns:
True is we modified this.

getKey

public byte[] getKey()
Do not use unless you have to. Used internally for compacting and testing. Use getRow(), getFamily(), getQualifier(), and getValue() if accessing a KeyValue client-side.

Returns:
Copy of the key portion only.

getValue

public byte[] getValue()
Returns value in a new byte array. Primarily for use client-side. If server-side, use getBuffer() with appropriate offsets and lengths instead to save on allocations.

Returns:
Value in a new byte array.

getValueAsByteBuffer

public ByteBuffer getValueAsByteBuffer()
Returns the value wrapped in a new ByteBuffer.

Returns:
the value

loadValue

public void loadValue(ByteBuffer dst)
               throws BufferOverflowException
Loads this object's value into the provided ByteBuffer.

Does not clear or flip the buffer.

Parameters:
dst - the buffer where to write the value
Throws:
BufferOverflowException - if there is insufficient space remaining in the buffer

getRow

public byte[] getRow()
Primarily for use client-side. Returns the row of this KeyValue in a new byte array.

If server-side, use getBuffer() with appropriate offsets and lengths instead.

Returns:
Row in a new byte array.

getTimestamp

public long getTimestamp()
Specified by:
getTimestamp in interface Cell
Returns:
Timestamp

getType

public byte getType()
Returns:
Type of this KeyValue.

getTypeByte

public byte getTypeByte()
Specified by:
getTypeByte in interface Cell
Returns:
KeyValue.TYPE byte representation

isDelete

public boolean isDelete()
Returns:
True if a delete type, a KeyValue.Type.Delete or a {KeyValue.Type#DeleteFamily} or a KeyValue.Type.DeleteColumn KeyValue type.

isDeleteType

public boolean isDeleteType()
Returns:
True if this KV is a KeyValue.Type.Delete type.

isDeleteFamily

public boolean isDeleteFamily()
Returns:
True if this KV is a delete family type.

isDeleteColumnOrFamily

public boolean isDeleteColumnOrFamily()
Returns:
True if this KV is a delete family or column type.

getFamily

public byte[] getFamily()
Primarily for use client-side. Returns the family of this KeyValue in a new byte array.

If server-side, use getBuffer() with appropriate offsets and lengths instead.

Returns:
Returns family. Makes a copy.

getQualifier

public byte[] getQualifier()
Primarily for use client-side. Returns the column qualifier of this KeyValue in a new byte array.

If server-side, use getBuffer() with appropriate offsets and lengths instead. Use getBuffer() with appropriate offsets and lengths instead.

Returns:
Returns qualifier. Makes a copy.

split

public KeyValue.SplitKeyValue split()

matchingFamily

public boolean matchingFamily(byte[] family)
Parameters:
family -
Returns:
True if matching families.

matchingFamily

public boolean matchingFamily(byte[] family,
                              int offset,
                              int length)

matchingFamily

public boolean matchingFamily(KeyValue other)

matchingQualifier

public boolean matchingQualifier(byte[] qualifier)
Parameters:
qualifier -
Returns:
True if matching qualifiers.

matchingQualifier

public boolean matchingQualifier(byte[] qualifier,
                                 int offset,
                                 int length)

matchingQualifier

public boolean matchingQualifier(KeyValue other)

matchingRow

public boolean matchingRow(byte[] row)

matchingRow

public boolean matchingRow(byte[] row,
                           int offset,
                           int length)

matchingRow

public boolean matchingRow(KeyValue other)

matchingColumnNoDelimiter

public boolean matchingColumnNoDelimiter(byte[] column)
Parameters:
column - Column minus its delimiter
Returns:
True if column matches.

matchingColumn

public boolean matchingColumn(byte[] family,
                              byte[] qualifier)
Parameters:
family - column family
qualifier - column qualifier
Returns:
True if column matches

matchingColumn

public boolean matchingColumn(byte[] family,
                              int foffset,
                              int flength,
                              byte[] qualifier,
                              int qoffset,
                              int qlength)
Checks if column matches.

Parameters:
family - family name
foffset - family offset
flength - family length
qualifier - column qualifier
qoffset - qualifier offset
qlength - qualifier length
Returns:
True if column matches

nonNullRowAndColumn

public boolean nonNullRowAndColumn()
Returns:
True if non-null row and column.

isEmptyColumn

public boolean isEmptyColumn()
Returns:
True if column is empty.

createKeyOnly

public KeyValue createKeyOnly(boolean lenAsVal)
Creates a new KeyValue that only contains the key portion (the value is set to be null).

Parameters:
lenAsVal - replace value with the actual value length (false=empty)

parseColumn

public static byte[][] parseColumn(byte[] c)
Splits a column in family:qualifier form into separate byte arrays.

Not recommend to be used as this is old-style API.

Parameters:
c - The column.
Returns:
The parsed column.

makeColumn

public static byte[] makeColumn(byte[] family,
                                byte[] qualifier)
Makes a column in family:qualifier form from separate byte arrays.

Not recommended for usage as this is old-style API.

Parameters:
family -
qualifier -
Returns:
family:qualifier

getFamilyDelimiterIndex

public static int getFamilyDelimiterIndex(byte[] b,
                                          int offset,
                                          int length)
Parameters:
b -
Returns:
Index of the family-qualifier colon delimiter character in passed buffer.

getDelimiter

public static int getDelimiter(byte[] b,
                               int offset,
                               int length,
                               int delimiter)
Parameters:
b -
delimiter -
Returns:
Index of delimiter having started from start of b moving rightward.

getDelimiterInReverse

public static int getDelimiterInReverse(byte[] b,
                                        int offset,
                                        int length,
                                        int delimiter)
Find index of passed delimiter walking from end of buffer backwards.

Parameters:
b -
delimiter -
Returns:
Index of delimiter

createLastOnRow

public static KeyValue createLastOnRow(byte[] row)
Creates a KeyValue that is last on the specified row id. That is, every other possible KeyValue for the given row would compareTo() less than the result of this call.

Parameters:
row - row key
Returns:
Last possible KeyValue on passed row

createFirstOnRow

public static KeyValue createFirstOnRow(byte[] row)
Create a KeyValue that is smaller than all other possible KeyValues for the given row. That is any (valid) KeyValue on 'row' would sort _after_ the result.

Parameters:
row - - row key (arbitrary byte array)
Returns:
First possible KeyValue on passed row

createFirstOnRow

public static KeyValue createFirstOnRow(byte[] row,
                                        int roffset,
                                        short rlength)
Create a KeyValue that is smaller than all other possible KeyValues for the given row. That is any (valid) KeyValue on 'row' would sort _after_ the result.

Parameters:
row - - row key (arbitrary byte array)
Returns:
First possible KeyValue on passed row

createFirstOnRow

public static KeyValue createFirstOnRow(byte[] row,
                                        long ts)
Creates a KeyValue that is smaller than all other KeyValues that are older than the passed timestamp.

Parameters:
row - - row key (arbitrary byte array)
ts - - timestamp
Returns:
First possible key on passed row and timestamp.

createFirstOnRow

public 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. Used for seeking.

Parameters:
row - - row key (arbitrary byte array)
family - - family name
qualifier - - column qualifier
Returns:
First possible key on passed row, and column.

createFirstDeleteFamilyOnRow

public static KeyValue createFirstDeleteFamilyOnRow(byte[] row,
                                                    byte[] family)
Create a Delete Family KeyValue for the specified row and family that would be smaller than all other possible Delete Family KeyValues that have the same row and family. Used for seeking.

Parameters:
row - - row key (arbitrary byte array)
family - - family name
Returns:
First Delete Family possible key on passed row.

createFirstOnRow

public static KeyValue createFirstOnRow(byte[] row,
                                        byte[] f,
                                        byte[] q,
                                        long ts)
Parameters:
row - - row key (arbitrary byte array)
f - - family name
q - - column qualifier
ts - - timestamp
Returns:
First possible key on passed row, column and timestamp

createFirstOnRow

public static KeyValue createFirstOnRow(byte[] row,
                                        int roffset,
                                        int rlength,
                                        byte[] family,
                                        int foffset,
                                        int flength,
                                        byte[] qualifier,
                                        int qoffset,
                                        int qlength)
Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier. Used for seeking.

Parameters:
row - row key
roffset - row offset
rlength - row length
family - family name
foffset - family offset
flength - family length
qualifier - column qualifier
qoffset - qualifier offset
qlength - qualifier length
Returns:
First possible key on passed Row, Family, Qualifier.

createFirstOnRow

public static KeyValue createFirstOnRow(byte[] buffer,
                                        byte[] row,
                                        byte[] family,
                                        byte[] qualifier)
                                 throws IllegalArgumentException
Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier. Used for seeking.

Parameters:
buffer - the buffer to use for the new KeyValue object
row - the value key
family - family name
qualifier - column qualifier
Returns:
First possible key on passed Row, Family, Qualifier.
Throws:
IllegalArgumentException - The resulting KeyValue object would be larger than the provided buffer or than Integer.MAX_VALUE

createFirstOnRow

public static KeyValue createFirstOnRow(byte[] buffer,
                                        int boffset,
                                        byte[] row,
                                        int roffset,
                                        int rlength,
                                        byte[] family,
                                        int foffset,
                                        int flength,
                                        byte[] qualifier,
                                        int qoffset,
                                        int qlength)
                                 throws IllegalArgumentException
Create a KeyValue for the specified row, family and qualifier that would be smaller than all other possible KeyValues that have the same row, family, qualifier. Used for seeking.

Parameters:
buffer - the buffer to use for the new KeyValue object
boffset - buffer offset
row - the value key
roffset - row offset
rlength - row length
family - family name
foffset - family offset
flength - family length
qualifier - column qualifier
qoffset - qualifier offset
qlength - qualifier length
Returns:
First possible key on passed Row, Family, Qualifier.
Throws:
IllegalArgumentException - The resulting KeyValue object would be larger than the provided buffer or than Integer.MAX_VALUE

createLastOnRow

public static KeyValue createLastOnRow(byte[] row,
                                       int roffset,
                                       int rlength,
                                       byte[] family,
                                       int foffset,
                                       int flength,
                                       byte[] qualifier,
                                       int qoffset,
                                       int qlength)
Create a KeyValue for the specified row, family and qualifier that would be larger than or equal to all other possible KeyValues that have the same row, family, qualifier. Used for reseeking.

Parameters:
row - row key
roffset - row offset
rlength - row length
family - family name
foffset - family offset
flength - family length
qualifier - column qualifier
qoffset - qualifier offset
qlength - qualifier length
Returns:
Last possible key on passed row, family, qualifier.

createLastOnRowCol

public KeyValue createLastOnRowCol()
Similar to createLastOnRow(byte[], int, int, byte[], int, int, byte[], int, int) but creates the last key on the row/column of this KV (the value part of the returned KV is always empty). Used in creating "fake keys" for the multi-column Bloom filter optimization to skip the row/column we already know is not in the file.

Returns:
the last key on the row/column of the given key-value pair

createFirstOnRowColTS

public KeyValue createFirstOnRowColTS(long ts)
Creates the first KV with the row/family/qualifier of this KV and the given timestamp. Uses the "maximum" KV type that guarantees that the new KV is the lowest possible for this combination of row, family, qualifier, and timestamp. This KV's own timestamp is ignored. While this function copies the value from this KV, it is normally used on key-only KVs.


createKeyValueFromKey

public static KeyValue createKeyValueFromKey(byte[] b)
Parameters:
b -
Returns:
A KeyValue made of a byte array that holds the key-only part. Needed to convert hfile index members to KeyValues.

createKeyValueFromKey

public static KeyValue createKeyValueFromKey(ByteBuffer bb)
Parameters:
bb -
Returns:
A KeyValue made of a byte buffer that holds the key-only part. Needed to convert hfile index members to KeyValues.

createKeyValueFromKey

public static KeyValue createKeyValueFromKey(byte[] b,
                                             int o,
                                             int l)
Parameters:
b -
o -
l -
Returns:
A KeyValue made of a byte array that holds the key-only part. Needed to convert hfile index members to KeyValues.

create

public static KeyValue create(DataInput in)
                       throws IOException
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 in OR if we find a length of zero, we will return null which can be useful marking a stream as done.
Throws:
IOException

create

public static KeyValue create(int length,
                              DataInput in)
                       throws IOException
Create a KeyValue reading length from in

Parameters:
length -
in -
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

iscreate

public static KeyValue iscreate(InputStream in)
                         throws IOException
Create a KeyValue reading from the raw InputStream. Named iscreate so doesn't clash with create(DataInput)

Parameters:
in -
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

write

public static long write(KeyValue kv,
                         DataOutput out)
                  throws IOException
Write out a KeyValue in the manner in which we used to when KeyValue was a Writable.

Parameters:
kv -
out -
Returns:
Length written on stream
Throws:
IOException
See Also:
for the inverse function

oswrite

public static long oswrite(KeyValue kv,
                           OutputStream out)
                    throws IOException
Write out a KeyValue in the manner in which we used to when KeyValue was a Writable but do not require a DataOutput, just take plain OutputStream Named oswrite so does not clash with write(KeyValue, DataOutput)

Parameters:
kv -
out -
Returns:
Length written on stream
Throws:
IOException
See Also:
for the inverse function, write(KeyValue, DataOutput)

heapSize

public long heapSize()
HeapSize implementation We do not count the bytes in the rowCache because it should be empty for a KeyValue in the MemStore.

Specified by:
heapSize in interface HeapSize
Returns:
Approximate 'exclusive deep size' of implementing object. Includes count of payload and hosting object sizings.


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.