Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Duplicate
-
0.20.1
-
None
-
None
-
I added an example of this in a Get in the Data Model section of book.xml a few patches ago
Description
The implicit support HBase provides for versioning of values is very powerful, but it's not all that obvious for application programmers to use it to obtain the historical values.
I would like to suggest adding some comments and sample code to the Result class (org.apache.hadoop.hbase.client.Result) Javadoc. I know this seems sort of obvious to people that regularly use HBase, but I think that for new folks having code examples available in Javadoc is helpful because it's "one stop shopping" for documentation (i.e., as opposed to looking to an external writeup). Arguably, this type of example could also go in the HTable class javadoc.
e.g.,....
HTable table = new HTable(config, "mytable");
Scan scan = new Scan(); // no arguments indicates will scan all rows
scan.setMaxVersions( 5 ); // setting this to 1 only returns current version
ResultScanner rs = table.getScanner(scan);
for (Iterator<Result> i = rs.iterator(); i.hasNext(); ) {
Result r = i.next();
// obtains current value from 'family:column'
byte b[] = r.getValue( Bytes.toBytes("family"), Bytes.toBytes("column") );
KeyValue kv[] = r.raw();
for (int j = 0; j < kv.length; j++)
}