|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.hadoop.hbase.client.Result
public class Result
Single row result of a Get
or Scan
query.
This class is NOT THREAD SAFE.
Convenience methods are available that return various Map
structures and values directly.
To get a complete mapping of all cells in the Result, which can include
multiple families and multiple versions, use getMap()
.
To get a mapping of each family to its columns (qualifiers and values),
including only the latest version of each, use getNoVersionMap()
.
To get a mapping of qualifiers to latest values for an individual family use
getFamilyMap(byte[])
.
To get the latest value for a specific family and qualifier use getValue(byte[], byte[])
.
A Result is backed by an array of KeyValue
objects, each representing
an HBase cell defined by the row, family, qualifier, timestamp, and value.
The underlying KeyValue
objects can be accessed through the methods
sorted()
and list()
. Each KeyValue can then be accessed
through KeyValue.getRow()
, KeyValue.getFamily()
, KeyValue.getQualifier()
,
KeyValue.getTimestamp()
, and KeyValue.getValue()
.
Constructor Summary | |
---|---|
Result()
Constructor used for Writable. |
|
Result(ImmutableBytesWritable bytes)
Instantiate a Result from the specified raw binary format. |
|
Result(KeyValue[] kvs)
Instantiate a Result with the specified array of KeyValues. |
|
Result(List<KeyValue> kvs)
Instantiate a Result with the specified List of KeyValues. |
Method Summary | |
---|---|
protected int |
binarySearch(KeyValue[] kvs,
byte[] family,
byte[] qualifier)
|
static void |
compareResults(Result res1,
Result res2)
Does a deep comparison of two Results, down to the byte arrays. |
boolean |
containsColumn(byte[] family,
byte[] qualifier)
Checks for existence of the specified column. |
ImmutableBytesWritable |
getBytes()
Returns the raw binary encoding of this Result. |
List<KeyValue> |
getColumn(byte[] family,
byte[] qualifier)
Return the KeyValues for the specific column. |
KeyValue |
getColumnLatest(byte[] family,
byte[] qualifier)
The KeyValue for the most recent for a given column. |
NavigableMap<byte[],byte[]> |
getFamilyMap(byte[] family)
Map of qualifiers to values. |
NavigableMap<byte[],NavigableMap<byte[],NavigableMap<Long,byte[]>>> |
getMap()
Map of families to all versions of its qualifiers and values. |
NavigableMap<byte[],NavigableMap<byte[],byte[]>> |
getNoVersionMap()
Map of families to their most recent qualifiers and values. |
byte[] |
getRow()
Method for retrieving the row that this result is for |
byte[] |
getValue(byte[] family,
byte[] qualifier)
Get the latest version of the specified column. |
long |
getWritableSize()
Provide a size hint to the caller. |
static long |
getWriteArraySize(Result[] results)
|
boolean |
isEmpty()
Check if the underlying KeyValue [] is empty or not |
List<KeyValue> |
list()
Create a sorted list of the KeyValue's in this result. |
KeyValue[] |
raw()
Return the array of KeyValues backing this Result instance. |
static Result[] |
readArray(DataInput in)
|
void |
readFields(DataInput in)
|
int |
size()
|
KeyValue[] |
sorted()
Deprecated. |
String |
toString()
|
byte[] |
value()
Returns the value of the first column in the Result. |
void |
write(DataOutput out)
|
static void |
writeArray(DataOutput out,
Result[] results)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Result()
public Result(KeyValue[] kvs)
kvs
- array of KeyValuespublic Result(List<KeyValue> kvs)
kvs
- List of KeyValuespublic Result(ImmutableBytesWritable bytes)
bytes
- raw binary format of ResultMethod Detail |
---|
public byte[] getRow()
public KeyValue[] raw()
KeyValue.COMPARATOR
.
The array only contains what your Get or Scan specifies and no more.
For example if you request column "A" 1 version you will have at most 1
KeyValue in the array. If you request column "A" with 2 version you will
have at most 2 KeyValues, with the first one being the newer timestamp and
the second being the older timestamp (this is the sort order defined by
KeyValue.COMPARATOR
). If columns don't exist, they won't be
present in the result. Therefore if you ask for 1 version all columns,
it is safe to iterate over this array and expect to see 1 KeyValue for
each column and no more.
This API is faster than using getFamilyMap() and getMap()
public List<KeyValue> list()
public KeyValue[] sorted()
Since HBase 0.20.5 this is equivalent to raw()
. Use
raw()
instead.
public List<KeyValue> getColumn(byte[] family, byte[] qualifier)
KeyValue.COMPARATOR
order. That implies the first entry in
the list is the most recent column. If the query (Scan or Get) only
requested 1 version the list will contain at most 1 entry. If the column
did not exist in the result set (either the column does not exist
or the column was not selected in the query) the list will be empty.
Also see getColumnLatest which returns just a KeyValue
family
- the familyqualifier
-
protected int binarySearch(KeyValue[] kvs, byte[] family, byte[] qualifier)
public KeyValue getColumnLatest(byte[] family, byte[] qualifier)
family
- qualifier
-
public byte[] getValue(byte[] family, byte[] qualifier)
family
- family namequalifier
- column qualifier
public boolean containsColumn(byte[] family, byte[] qualifier)
family
- family namequalifier
- column qualifier
public NavigableMap<byte[],NavigableMap<byte[],NavigableMap<Long,byte[]>>> getMap()
Returns a three level Map of the form:
Map&family,Map<qualifier,Map<timestamp,value>>>
Note: All other map returning methods make use of this map internally.
public NavigableMap<byte[],NavigableMap<byte[],byte[]>> getNoVersionMap()
Returns a two level Map of the form: Map&family,Map<qualifier,value>>
The most recent version of each qualifier will be used.
public NavigableMap<byte[],byte[]> getFamilyMap(byte[] family)
Returns a Map of the form: Map<qualifier,value>
family
- column family to get
public byte[] value()
public ImmutableBytesWritable getBytes()
Please note, there may be an offset into the underlying byte array of the
returned ImmutableBytesWritable. Be sure to use both
ImmutableBytesWritable.get()
and ImmutableBytesWritable.getOffset()
public boolean isEmpty()
public int size()
public String toString()
toString
in class Object
public void readFields(DataInput in) throws IOException
readFields
in interface org.apache.hadoop.io.Writable
IOException
public long getWritableSize()
WritableWithSize
getWritableSize
in interface WritableWithSize
public void write(DataOutput out) throws IOException
write
in interface org.apache.hadoop.io.Writable
IOException
public static long getWriteArraySize(Result[] results)
public static void writeArray(DataOutput out, Result[] results) throws IOException
IOException
public static Result[] readArray(DataInput in) throws IOException
IOException
public static void compareResults(Result res1, Result res2) throws Exception
res1
- first result to compareres2
- second result to compare
Exception
- Every difference is throwing an exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |