@InterfaceAudience.Public @InterfaceStability.Stable public class Result extends Object implements CellScannable, CellScanner
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 Cell
objects, each representing
an HBase cell defined by the row, family, qualifier, timestamp, and value.
The underlying Cell
objects can be accessed through the method listCells()
.
This will create a List from the internal Cell []. Better is to exploit the fact that
a new Result instance is a primed CellScanner
; just call advance()
and
current()
to iterate over Cells as you would any CellScanner
.
Call cellScanner()
to reset should you need to iterate the same Result over again
(CellScanner
s are one-shot).
If you need to overwrite a Result with another Result instance -- as in the old 'mapred'
RecordReader next invocations -- then create an empty Result with the null constructor and
in then use copyFrom(Result)
Modifier and Type | Field and Description |
---|---|
static Result |
EMPTY_RESULT |
Constructor and Description |
---|
Result()
Creates an empty Result w/ no KeyValue payload; returns null if you call
rawCells() . |
Result(KeyValue[] cells)
Deprecated.
Use
create(List) instead. |
Result(List<KeyValue> kvs)
Deprecated.
Use
create(List) instead. |
Modifier and Type | Method and Description |
---|---|
void |
addResults(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.RegionLoadStats loadStats)
Deprecated.
use
setStatistics(ClientProtos.RegionLoadStats) instead |
boolean |
advance()
Advance the scanner 1 cell.
|
protected int |
binarySearch(Cell[] kvs,
byte[] family,
byte[] qualifier) |
protected int |
binarySearch(Cell[] kvs,
byte[] family,
int foffset,
int flength,
byte[] qualifier,
int qoffset,
int qlength)
Searches for the latest value for the specified column.
|
CellScanner |
cellScanner() |
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 a value for the specified column (empty or not).
|
boolean |
containsColumn(byte[] family,
int foffset,
int flength,
byte[] qualifier,
int qoffset,
int qlength)
Checks for existence of a value for the specified column (empty or not).
|
boolean |
containsEmptyColumn(byte[] family,
byte[] qualifier)
Checks if the specified column contains an empty value (a zero-length byte array).
|
boolean |
containsEmptyColumn(byte[] family,
int foffset,
int flength,
byte[] qualifier,
int qoffset,
int qlength)
Checks if the specified column contains an empty value (a zero-length byte array).
|
boolean |
containsNonEmptyColumn(byte[] family,
byte[] qualifier)
Checks if the specified column contains a non-empty value (not a zero-length byte array).
|
boolean |
containsNonEmptyColumn(byte[] family,
int foffset,
int flength,
byte[] qualifier,
int qoffset,
int qlength)
Checks if the specified column contains a non-empty value (not a zero-length byte array).
|
void |
copyFrom(Result other)
Copy another Result into this one.
|
static Result |
create(Cell[] cells)
Instantiate a Result with the specified array of KeyValues.
|
static Result |
create(Cell[] cells,
Boolean exists,
boolean stale) |
static Result |
create(Cell[] cells,
Boolean exists,
boolean stale,
boolean mayHaveMoreCellsInRow) |
static Result |
create(List<Cell> cells)
Instantiate a Result with the specified List of KeyValues.
|
static Result |
create(List<Cell> cells,
Boolean exists) |
static Result |
create(List<Cell> cells,
Boolean exists,
boolean stale) |
static Result |
create(List<Cell> cells,
Boolean exists,
boolean stale,
boolean partial) |
static Result |
createCompleteResult(Iterable<Result> partialResults)
Forms a single result from the partial results in the partialResults list.
|
static Result |
createCompleteResult(List<Result> partialResults)
Deprecated.
|
static Result |
createCursorResult(Cursor cursor) |
Cell |
current() |
List<KeyValue> |
getColumn(byte[] family,
byte[] qualifier)
Deprecated.
Use
getColumnCells(byte[], byte[]) instead. |
List<Cell> |
getColumnCells(byte[] family,
byte[] qualifier)
Return the Cells for the specific column.
|
KeyValue |
getColumnLatest(byte[] family,
byte[] qualifier)
Deprecated.
Use
getColumnLatestCell(byte[], byte[]) instead. |
KeyValue |
getColumnLatest(byte[] family,
int foffset,
int flength,
byte[] qualifier,
int qoffset,
int qlength)
Deprecated.
|
Cell |
getColumnLatestCell(byte[] family,
byte[] qualifier)
The Cell for the most recent timestamp for a given column.
|
Cell |
getColumnLatestCell(byte[] family,
int foffset,
int flength,
byte[] qualifier,
int qoffset,
int qlength)
The Cell for the most recent timestamp for a given column.
|
Cursor |
getCursor()
Return the cursor if this Result is a cursor result.
|
Boolean |
getExists() |
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.
|
org.apache.hadoop.hbase.protobuf.generated.ClientProtos.RegionLoadStats |
getStats()
Deprecated.
|
static long |
getTotalSizeOfCells(Result result)
Get total size of raw cells
|
byte[] |
getValue(byte[] family,
byte[] qualifier)
Get the latest version of the specified column.
|
ByteBuffer |
getValueAsByteBuffer(byte[] family,
byte[] qualifier)
Returns the value wrapped in a new
ByteBuffer . |
ByteBuffer |
getValueAsByteBuffer(byte[] family,
int foffset,
int flength,
byte[] qualifier,
int qoffset,
int qlength)
Returns the value wrapped in a new
ByteBuffer . |
boolean |
isCursor()
Return true if this Result is a cursor to tell users where the server has scanned.
|
boolean |
isEmpty()
Check if the underlying Cell [] is empty or not
|
boolean |
isPartial()
Deprecated.
the word 'partial' ambiguous, use
mayHaveMoreCellsInRow() instead.
Deprecated since 1.4.0. |
boolean |
isStale()
Whether or not the results are coming from possibly stale data.
|
List<KeyValue> |
list()
Deprecated.
as of 0.96, use
listCells() |
List<Cell> |
listCells()
Create a sorted list of the Cell's in this result.
|
boolean |
loadValue(byte[] family,
byte[] qualifier,
ByteBuffer dst)
Loads the latest version of the specified column into the provided
ByteBuffer . |
boolean |
loadValue(byte[] family,
int foffset,
int flength,
byte[] qualifier,
int qoffset,
int qlength,
ByteBuffer dst)
Loads the latest version of the specified column into the provided
ByteBuffer . |
boolean |
mayHaveMoreCellsInRow()
For scanning large rows, the RS may choose to return the cells chunk by chunk to prevent OOM
or timeout.
|
KeyValue[] |
raw()
Deprecated.
as of 0.96, use
rawCells() |
Cell[] |
rawCells()
Return the array of Cells backing this Result instance.
|
void |
setExists(Boolean exists) |
void |
setStatistics(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.RegionLoadStats loadStats)
Deprecated.
|
int |
size() |
String |
toString() |
byte[] |
value()
Returns the value of the first column in the Result.
|
public static final Result EMPTY_RESULT
public Result()
rawCells()
.
Use this to represent no results if null
won't do or in old 'mapred' as oppposed to 'mapreduce' package
MapReduce where you need to overwrite a Result
instance with a copyFrom(Result)
call.@Deprecated public Result(KeyValue[] cells)
create(List)
instead.@Deprecated public Result(List<KeyValue> kvs)
create(List)
instead.public static Result create(List<Cell> cells)
cells
- List of cellspublic static Result create(List<Cell> cells, Boolean exists, boolean stale, boolean partial)
public static Result create(Cell[] cells)
cells
- array of cellspublic static Result create(Cell[] cells, Boolean exists, boolean stale, boolean mayHaveMoreCellsInRow)
public byte[] getRow()
public Cell[] rawCells()
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
Cell in the array. If you request column "A" with 2 version you will
have at most 2 Cells, 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 Cell for
each column and no more.
This API is faster than using getFamilyMap() and getMap()@Deprecated public KeyValue[] raw()
rawCells()
public List<Cell> listCells()
@Deprecated public List<KeyValue> list()
listCells()
@Deprecated public List<KeyValue> getColumn(byte[] family, byte[] qualifier)
getColumnCells(byte[], byte[])
instead.public List<Cell> getColumnCells(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 Cellfamily
- the familyqualifier
- protected int binarySearch(Cell[] kvs, byte[] family, byte[] qualifier)
protected int binarySearch(Cell[] kvs, byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength)
kvs
- the array to searchfamily
- family namefoffset
- family offsetflength
- family lengthqualifier
- column qualifierqoffset
- qualifier offsetqlength
- qualifier length@Deprecated public KeyValue getColumnLatest(byte[] family, byte[] qualifier)
getColumnLatestCell(byte[], byte[])
instead.public Cell getColumnLatestCell(byte[] family, byte[] qualifier)
family
- qualifier
- @Deprecated public KeyValue getColumnLatest(byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength)
getColumnLatestCell(byte[], int, int, byte[], int, int)
instead.public Cell getColumnLatestCell(byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength)
family
- family namefoffset
- family offsetflength
- family lengthqualifier
- column qualifierqoffset
- qualifier offsetqlength
- qualifier lengthpublic byte[] getValue(byte[] family, byte[] qualifier)
getValueAsByteBuffer(byte[], byte[])
, etc., or listCells()
if you would
avoid the cloning.family
- family namequalifier
- column qualifierpublic ByteBuffer getValueAsByteBuffer(byte[] family, byte[] qualifier)
ByteBuffer
.family
- family namequalifier
- column qualifiernull
if none foundpublic ByteBuffer getValueAsByteBuffer(byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength)
ByteBuffer
.family
- family namefoffset
- family offsetflength
- family lengthqualifier
- column qualifierqoffset
- qualifier offsetqlength
- qualifier lengthnull
if none foundpublic boolean loadValue(byte[] family, byte[] qualifier, ByteBuffer dst) throws BufferOverflowException
ByteBuffer
.
Does not clear or flip the buffer.
family
- family namequalifier
- column qualifierdst
- the buffer where to write the valuetrue
if a value was found, false
otherwiseBufferOverflowException
- there is insufficient space remaining in the bufferpublic boolean loadValue(byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength, ByteBuffer dst) throws BufferOverflowException
ByteBuffer
.
Does not clear or flip the buffer.
family
- family namefoffset
- family offsetflength
- family lengthqualifier
- column qualifierqoffset
- qualifier offsetqlength
- qualifier lengthdst
- the buffer where to write the valuetrue
if a value was found, false
otherwiseBufferOverflowException
- there is insufficient space remaining in the bufferpublic boolean containsNonEmptyColumn(byte[] family, byte[] qualifier)
family
- family namequalifier
- column qualifierpublic boolean containsNonEmptyColumn(byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength)
family
- family namefoffset
- family offsetflength
- family lengthqualifier
- column qualifierqoffset
- qualifier offsetqlength
- qualifier lengthpublic boolean containsEmptyColumn(byte[] family, byte[] qualifier)
family
- family namequalifier
- column qualifierpublic boolean containsEmptyColumn(byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength)
family
- family namefoffset
- family offsetflength
- family lengthqualifier
- column qualifierqoffset
- qualifier offsetqlength
- qualifier lengthpublic boolean containsColumn(byte[] family, byte[] qualifier)
family
- family namequalifier
- column qualifierpublic boolean containsColumn(byte[] family, int foffset, int flength, byte[] qualifier, int qoffset, int qlength)
family
- family namefoffset
- family offsetflength
- family lengthqualifier
- column qualifierqoffset
- qualifier offsetqlength
- qualifier lengthpublic 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 boolean isEmpty()
public int size()
public static void compareResults(Result res1, Result res2) throws Exception
res1
- first result to compareres2
- second result to compareException
- Every difference is throwing an exception@Deprecated public static Result createCompleteResult(List<Result> partialResults) throws IOException
partialResults
- list of partial resultsIOException
- A complete result cannot be formed because the results in the partial list
come from different rowspublic static Result createCompleteResult(Iterable<Result> partialResults) throws IOException
partialResults
- iterable of partial resultsIOException
- A complete result cannot be formed because the results in the partial list
come from different rowspublic static long getTotalSizeOfCells(Result result)
result
- public void copyFrom(Result other)
other
- UnsupportedOperationException
- if invoked on instance of EMPTY_RESULT
(which is supposed to be immutable).public CellScanner cellScanner()
cellScanner
in interface CellScannable
Cell
spublic Cell current()
current
in interface CellScanner
public boolean advance()
CellScanner
advance
in interface CellScanner
CellScanner.current()
will return a valid Cellpublic Boolean getExists()
public void setExists(Boolean exists)
public boolean isStale()
Consistency
is not STRONG for the query.@Deprecated public boolean isPartial()
mayHaveMoreCellsInRow()
instead.
Deprecated since 1.4.0.mayHaveMoreCellsInRow()
public boolean mayHaveMoreCellsInRow()
Scan.setAllowPartialResults(boolean)
or Scan.setBatch(int)
,
this method will always return false because the Result must contains all cells in one Row.@InterfaceAudience.Private @Deprecated public void addResults(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.RegionLoadStats loadStats)
setStatistics(ClientProtos.RegionLoadStats)
insteadloadStats
- statistics about the current region from which this was returnedUnsupportedOperationException
- if invoked on instance of EMPTY_RESULT
(which is supposed to be immutable).@InterfaceAudience.Private @Deprecated public void setStatistics(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.RegionLoadStats loadStats)
loadStats
- statistics about the current region from which this was returned@Deprecated public org.apache.hadoop.hbase.protobuf.generated.ClientProtos.RegionLoadStats getStats()
public boolean isCursor()
getCursor()
.
while (r = scanner.next() && r != null) {
if(r.isCursor()){
// scanning is not end, it is a cursor, save its row key and close scanner if you want, or
// just continue the loop to call next().
} else {
// just like before
}
}
// scanning is end
Scan.setNeedCursorResult(boolean)
Cursor
getCursor()
public Cursor getCursor()
Scan.setNeedCursorResult(boolean)
Cursor
isCursor()
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.