public final class KeyValue extends Object implements Comparable<KeyValue>
This represents one unit of HBase data, one "record".
byte
arraysbyte[]
that's given to it, neither
will it create a copy before returning one to you.
Changing a byte array get from or pass to this class will have
unpredictable consequences. In particular, multiple
KeyValue
instances may share the same byte arrays, so changing
one instance may also unexpectedly affect others.Modifier and Type | Field and Description |
---|---|
static long |
TIMESTAMP_NOW
Timestamp value to let the server set the timestamp at processing time.
|
Constructor and Description |
---|
KeyValue(byte[] key,
byte[] family,
byte[] qualifier,
byte[] value)
Constructor.
|
KeyValue(byte[] key,
byte[] family,
byte[] qualifier,
long timestamp,
byte[] value)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(KeyValue other) |
boolean |
equals(Object other) |
byte[] |
family()
Returns the column family.
|
static KeyValue |
fromBuffer(ChannelBuffer buf,
KeyValue prev)
De-serializes
KeyValue from a buffer (HBase 0.94 and before). |
int |
hashCode() |
byte[] |
key()
Returns the row key.
|
byte[] |
qualifier()
Returns the column qualifier.
|
long |
timestamp()
Returns the timestamp stored in this
KeyValue . |
String |
toString() |
byte[] |
value()
Returns the value, the contents of the cell.
|
public static final long TIMESTAMP_NOW
KeyValue
, the server
will substitute a real timestamp at the time it processes it. HBase uses
current UNIX time in milliseconds.public KeyValue(byte[] key, byte[] family, byte[] qualifier, long timestamp, byte[] value)
key
- The row key. Length must fit in 16 bits.family
- The column family. Length must fit in 8 bits.qualifier
- The column qualifier.timestamp
- Timestamp on the value. This timestamp can be set to
guarantee ordering of values or operations. It is strongly advised to
use a UNIX timestamp in milliseconds, e.g. from a source such as
System.currentTimeMillis()
. This value must be strictly positive.value
- The value, the contents of the cell.IllegalArgumentException
- if any argument is invalid (e.g. array
size is too long) or if the timestamp is negative.public KeyValue(byte[] key, byte[] family, byte[] qualifier, byte[] value)
This KeyValue
will be timestamped by the server at the time
the server processes it.
key
- The row key. Length must fit in 16 bits.family
- The column family. Length must fit in 8 bits.qualifier
- The column qualifier.value
- The value, the contents of the cell.IllegalArgumentException
- if any argument is invalid (e.g. array
size is too long).TIMESTAMP_NOW
public byte[] key()
public byte[] family()
public byte[] qualifier()
public long timestamp()
KeyValue
.TIMESTAMP_NOW
public byte[] value()
public int compareTo(KeyValue other)
compareTo
in interface Comparable<KeyValue>
public static KeyValue fromBuffer(ChannelBuffer buf, KeyValue prev)
KeyValue
from a buffer (HBase 0.94 and before).buf
- The buffer to de-serialize from.prev
- Another KeyValue
previously de-serialized from the
same buffer. Can be null
. The idea here is that KeyValues
often come in a sorted batch, and often share a number of byte arrays
(e.g. they all have the same row key and/or same family...). When
you specify another KeyValue, its byte arrays will be re-used in order
to avoid having too much duplicate data in memory. This costs a little
bit of CPU time to compare the arrays but saves memory (which in turns
saves CPU time later).null
).IllegalArgumentException
- if the buffer seems to contain a
malformed KeyValue
.