org.apache.hadoop.hbase.client
Class Result

java.lang.Object
  extended by org.apache.hadoop.hbase.client.Result
All Implemented Interfaces:
org.apache.hadoop.io.Writable

public class Result
extends Object
implements org.apache.hadoop.io.Writable

Single row result of a Get or Scan query.

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
 boolean containsColumn(byte[] family, byte[] qualifier)
          Checks for existence of the specified column.
 ImmutableBytesWritable getBytes()
          Returns the raw binary encoding of this Result.
 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.
 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 unsorted array of KeyValues backing this Result instance.
static Result[] readArray(DataInput in)
           
 void readFields(DataInput in)
           
 int size()
           
 KeyValue[] sorted()
          Returns a sorted array of KeyValues in this Result.
 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

Result

public Result()
Constructor used for Writable.


Result

public Result(KeyValue[] kvs)
Instantiate a Result with the specified array of KeyValues.

Parameters:
kvs - array of KeyValues

Result

public Result(List<KeyValue> kvs)
Instantiate a Result with the specified List of KeyValues.

Parameters:
kvs - List of KeyValues

Result

public Result(ImmutableBytesWritable bytes)
Instantiate a Result from the specified raw binary format.

Parameters:
bytes - raw binary format of Result
Method Detail

getRow

public byte[] getRow()
Method for retrieving the row that this result is for

Returns:
row

raw

public KeyValue[] raw()
Return the unsorted array of KeyValues backing this Result instance.

Returns:
unsorted array of KeyValues

list

public List<KeyValue> list()
Create a sorted list of the KeyValue's in this result.

Returns:
The sorted list of KeyValue's.

sorted

public KeyValue[] sorted()
Returns a sorted array of KeyValues in this Result.

Note: Sorting is done in place, so the backing array will be sorted after calling this method.

Returns:
sorted array of KeyValues

getMap

public NavigableMap<byte[],NavigableMap<byte[],NavigableMap<Long,byte[]>>> getMap()
Map of families to all versions of its qualifiers and values.

Returns a three level Map of the form: Map>>

Note: All other map returning methods make use of this map internally.

Returns:
map from families to qualifiers to versions

getNoVersionMap

public NavigableMap<byte[],NavigableMap<byte[],byte[]>> getNoVersionMap()
Map of families to their most recent qualifiers and values.

Returns a two level Map of the form: Map>

The most recent version of each qualifier will be used.

Returns:
map from families to qualifiers and value

getFamilyMap

public NavigableMap<byte[],byte[]> getFamilyMap(byte[] family)
Map of qualifiers to values.

Returns a Map of the form: Map<qualifier,value>

Parameters:
family - column family to get
Returns:
map of qualifiers to values

getValue

public byte[] getValue(byte[] family,
                       byte[] qualifier)
Get the latest version of the specified column.

Parameters:
family - family name
qualifier - column qualifier
Returns:
value of latest version of column, null if none found

containsColumn

public boolean containsColumn(byte[] family,
                              byte[] qualifier)
Checks for existence of the specified column.

Parameters:
family - family name
qualifier - column qualifier
Returns:
true if at least one value exists in the result, false if not

value

public byte[] value()
Returns the value of the first column in the Result.

Returns:
value of the first column

getBytes

public ImmutableBytesWritable getBytes()
Returns the raw binary encoding of this Result.

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()

Returns:
pointer to raw binary of Result

isEmpty

public boolean isEmpty()
Check if the underlying KeyValue [] is empty or not

Returns:
true if empty

size

public int size()
Returns:
the size of the underlying KeyValue []

toString

public String toString()
Overrides:
toString in class Object
Returns:
String

readFields

public void readFields(DataInput in)
                throws IOException
Specified by:
readFields in interface org.apache.hadoop.io.Writable
Throws:
IOException

write

public void write(DataOutput out)
           throws IOException
Specified by:
write in interface org.apache.hadoop.io.Writable
Throws:
IOException

writeArray

public static void writeArray(DataOutput out,
                              Result[] results)
                       throws IOException
Throws:
IOException

readArray

public static Result[] readArray(DataInput in)
                          throws IOException
Throws:
IOException


Copyright © 2010 Apache Software Foundation. All Rights Reserved.