HBase 获取单元格的所有带时间戳的值

发布于 2024-12-08 20:25:59 字数 1046 浏览 0 评论 0原文

我的 hbase 实例中有以下场景

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

现在,如果您会看到,最后两次插入是针对相同的列族、相同的列和相同的键。但是如果我正确理解 hbase cf:c+row3 代表一个单元格,它将具有插入值的所有带时间戳的版本。

但是简单的扫描仅返回最近的值

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

如何获取单元格的所有带时间戳的值,或者如何执行基于时间范围的查询?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月如刀 2024-12-15 20:25:59

为了查看列的版本,您需要提供版本计数。

scan 'test', {VERSIONS => 3}

如果可用,将为您提供 2 个版本的列。您也可以在 get 中使用它:

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

为了获取特定时间的值,您也可以使用 TIMESTAMP 。

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

如果您需要获取2个时间戳“之间”的值,您应该使用 TimestampsFilter

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.

梦醒灬来后我 2024-12-15 20:25:59

要更改列族中允许的版本数,请使用以下命令:

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

然后添加另一个条目:

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

然后查看不同的版本:

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

将返回类似以下内容的内容:

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

以下是更多详细信息的链接:
https://learnhbase.wordpress.com/2013/03/02/ hbase-shell-命令/

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/.

孤独难免 2024-12-15 20:25:59

value4 的 cf:c 的行键“row3”应该是唯一的,否则会被覆盖:

hbase(main):052:0> scan 'mytable' , {COLUMN => 'cf1:1', VERSION => 3}
ROW                         COLUMN+CELL                                                                   
 1234                       column=cf1:1, timestamp=1405796300388, value=hello                            
1 row(s) in 0.0160 seconds

hbase(main):053:0> put 'mytable', 1234, 'cf1:1', 'wow!'
0 row(s) in 0.1020 seconds

值为“hello”的 cf1 的第 1 列被具有相同行键 1234 和值“wow!”的第二个 put 覆盖。

hbase(main):054:0> scan 'mytable', {COLUMN => 'cf1:1', VERSION => 3}
ROW                   COLUMN+CELL                                               
 1234                 column=cf1:1, timestamp=1405831703617, value=wow!         
2 row(s) in 0.0310 seconds

现在,第二个插入包含 cf1 第 1 列的新值“hey”,最后 3 个版本的扫描查询现在显示“哇!”和“嘿”,请不要按降序显示版本。

hbase(main):055:0> put 'mytable', 123, 'cf1:1', 'hey'

hbase(main):004:0> scan 'mytable', {COLUMN => 'cf1:1', VERSION => 3}
ROW                   COLUMN+CELL                                               
 123                  column=cf1:1, timestamp=1405831295769, value=hey          
 1234                 column=cf1:1, timestamp=1405831703617, value=wow!         

The row key 'row3' of cf:c for value4 should be unique otherwise it gets overwritten:

hbase(main):052:0> scan 'mytable' , {COLUMN => 'cf1:1', VERSION => 3}
ROW                         COLUMN+CELL                                                                   
 1234                       column=cf1:1, timestamp=1405796300388, value=hello                            
1 row(s) in 0.0160 seconds

hbase(main):053:0> put 'mytable', 1234, 'cf1:1', 'wow!'
0 row(s) in 0.1020 seconds

Column 1 of cf1 having a value of 'hello' is overwritten by second put with same row key 1234 and a value of 'wow!'

hbase(main):054:0> scan 'mytable', {COLUMN => 'cf1:1', VERSION => 3}
ROW                   COLUMN+CELL                                               
 1234                 column=cf1:1, timestamp=1405831703617, value=wow!         
2 row(s) in 0.0310 seconds

Now the second insert contained a new value 'hey' for column 1 of cf1 and the scan query for last 3 versions now shows 'wow!' and 'hey', please not the versions are displayed on descending order.

hbase(main):055:0> put 'mytable', 123, 'cf1:1', 'hey'

hbase(main):004:0> scan 'mytable', {COLUMN => 'cf1:1', VERSION => 3}
ROW                   COLUMN+CELL                                               
 123                  column=cf1:1, timestamp=1405831295769, value=hey          
 1234                 column=cf1:1, timestamp=1405831703617, value=wow!         
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文