Change the timestamp hbase collation to get the first version of a specific row

According to my requirements, I need to get the first version of a specific string in Hbase. Assume the following is Htable:

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

Suppose I want to get the first version of row (1) according to a timestamp. Firstly, is there any hbase java method for this purpose? Secondly, if there is no such method, can I change the sort order of the timestamp in DESC to retrieve such a cell, getting the latest version of row (1)? What is the problem of making this change to streamline the hbase time reference?

+5
source share
2 answers

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

Possible alternative solutions:

  • save the first value in a separate column. This will require different code to insert and update the cell.
  • manually set the time Long.MAX_VALUE - System.currentTimeMillis() . In this case, make sure that the maximum number of versions for the cell is large enough, otherwise the last values ​​will be HBase garbage collection.
  • save the timestamp as part of the string key and get the first value using Scan with PageFilter.
+4
source

Have you looked scan.setReverse (true)? Side notes, it is not available in older versions (we use 0.94.18) and is one of the motives for us to update.

+1
source

All Articles