Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change hbase timestamp sorting in order to get the first version of specific row

Tags:

java

nosql

hbase

According to my requirements I need to get the first version of specific row in Hbase. Suppose the following Htable:

row_key          cf1:c1           timestamp
----------------------------------------
1                  x                 t1
1                  x                 t2
1                  x                 t3
...

Suppose I want to retrieve the first version of row(1) according to timestamp. First, is there any hbase java method for this purpose? Second, if there is not such method can I change the sorting order of timestamp to DESC for retrieving such cell by getting the last version of row(1)? What is the concerns of doing this change to timestamp ordering of hbase?

like image 787
Ali Avatar asked May 25 '15 07:05

Ali


2 Answers

You can use Result.getColumnCells to get all the columns and then get the first one from the list.

Possible alternative solutions:

  • store the first value in a separate column. This will require different code for inserting and updating the cell though.
  • manually set timestamp to Long.MAX_VALUE - System.currentTimeMillis(). In this case make sure that the maximum number of versions for a cell is high enough otherwise the latest values will be garbage collected by HBase.
  • store timestamp as part of the row key and get the first value using Scan with PageFilter.
like image 190
kostya Avatar answered Sep 23 '22 14:09

kostya


Have you looked at scan.setReverse(true)? A side note, it's not available in older versions (we use 0.94.18) and is one of motivations for us to upgrade.

like image 23
Sergei Rodionov Avatar answered Sep 25 '22 14:09

Sergei Rodionov