public class Result extends Object implements org.apache.hadoop.io.Writable, WritableWithSize
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 method list()
.
Each KeyValue can then be accessed
through KeyValue.getRow()
, KeyValue.getFamily()
, KeyValue.getQualifier()
,
KeyValue.getTimestamp()
, and KeyValue.getValue()
.
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
void |
copyFrom(Result other)
Copy another Result into this one.
|
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 key that corresponds to
the row from which this Result was created.
|
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() |
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) |
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 Resultpublic 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 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 KeyValuefamily
- 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 qualifierpublic boolean containsColumn(byte[] family, byte[] qualifier)
family
- family namequalifier
- column qualifierpublic 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 getpublic 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 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 compareException
- Every difference is throwing an exceptionpublic void copyFrom(Result other)
other
- Copyright © 2014 The Apache Software Foundation. All Rights Reserved.