Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HBase getting all timestamped values for a cell

Tags:

hadoop

hbase

i have the following scenario in my hbase instance

hbase(main):002:0> create 'test', 'cf'
0 row(s) in 1.4690 seconds

hbase(main):003:0> put 'test', 'row1', 'cf:a', 'value1'
0 row(s) in 0.1480 seconds

hbase(main):004:0> put 'test', 'row2', 'cf:b', 'value2'
0 row(s) in 0.0070 seconds

hbase(main):005:0> put 'test', 'row3', 'cf:c', 'value3'
0 row(s) in 0.0120 seconds

hbase(main):006:0> put 'test', 'row3', 'cf:c', 'value4'
0 row(s) in 0.0070 seconds

Now if you will see, the last two inserts are for the same column family, same column and same key. But if i understand hbase properly cf:c+row3 represent a cell which will have all timestamped versions of inserted value.

But a simple scan return only recent value

hbase(main):010:0> scan 'test'       
ROW                   COLUMN+CELL                                               
 row1                 column=cf:a, timestamp=1317945279379, value=value1        
 row2                 column=cf:b, timestamp=1317945285731, value=value2        
 row3                 column=cf:c, timestamp=1317945301466, value=value4        
3 row(s) in 0.0250 seconds

How do i get all timestamped values for a cell, or how to perform time range based query?

like image 712
FUD Avatar asked Oct 07 '11 00:10

FUD


2 Answers

In order to see versions of a column you need to give the version count.

scan 'test', {VERSIONS => 3}

will give you 2 versions of columns if they are available. you can use it in get aswell :

get 'test', 'row3', {COLUMN => 'cf:c', VERSIONS => 3}

for getting the value of a spesific time you can use TIMESTAMP aswell.

get 'test', 'row3', {COLUMN => 'cf:c', TIMESTAMP => 1317945301466}

if you need to get values "between" 2 timestamps you should use TimestampsFilter.

like image 160
frail Avatar answered Sep 24 '22 15:09

frail


To change the number of versions allowed in a column family use the following command:

 alter 'test', NAME=>'cf', VERSIONS=>2

then add another entry:

put 'test', 'row1', 'cf:a2', 'value1e'

then see the different versions:

get 'test', 'row1', {COLUMN => 'cf:a2', VERSIONS => 2}

would return something like:

COLUMN                        CELL                                                                                
 cf:a2                        timestamp=1457947804214, value=value1e                                              
 cf:a2                        timestamp=1457947217039, value=value1d                                              
2 row(s) in 0.0090 seconds

Here is a link for more details: https://learnhbase.wordpress.com/2013/03/02/hbase-shell-commands/.

like image 43
timmy_stapler Avatar answered Sep 24 '22 15:09

timmy_stapler