如何从 HBase 中的某一行和某一列获取多个版本

发布于 2024-12-20 10:33:58 字数 113 浏览 1 评论 0原文

我们知道,hbase有一个特性,就是特定的Row和特定的Column可以通过时间戳记录最近的变化值。 所以我的问题是,如何使用任何 HBase 命令列出所有更改的值?我用谷歌搜索了很多,但没有找到任何有用的链接。

As we know, hbase has a feature that a specific Row and specific Column can record recent change values by timestamps.
So my question is, HOW TO list all the changed values using any HBase command? I googled a lot, but didn't find any useful links.

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

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

发布评论

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

评论(3

疑心病 2024-12-27 10:33:58

默认情况下不启用版本控制。所以你在创建表时指定了它。

create 'student',{NAME=>"personal",Versions=>5},'school'

此处为“个人”列启用了版本控制,但未为“学校”列启用了版本控制。

如果您描述表“对于 personal”,则可以看到

hbase(main):009:0> describe 'student'
Table student is ENABLED
student
COLUMN FAMILIES DESCRIPTION
{NAME => 'personal', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '5', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
{NAME => 'school', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}

它显示 VERSIONS =>; '5' 对于 school,它显示 VERSIONS =>; '1'

如果表已经创建,则可以更改

alter 'student',NAME=>'school',VERSIONS =>3

hbase(main):011:0> describe 'student'
Table student is ENABLED
student
COLUMN FAMILIES DESCRIPTION
{NAME => 'personal', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '5', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
{NAME => 'school', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}

它不显示 VERSIONS =>; '3' 按预期用于学校

将数据放入表中。在同一单元格中输入多次。然后扫描桌子。

put 'student','1','personal:name','kaushik'
put 'student','1','personal:name','kaushik_again'
put 'student','1','school:name','great_school'
put 'student','1','school:name','great_school_again'

scan 'student',{VERSIONS=>10}
ROW  COLUMN+CELL
 1   column=personal:name, timestamp=1443002303208, value=kaushik_again
 1   column=personal:name, timestamp=1443002294049, value=kaushik
 1   column=school:name, timestamp=1443002320753, value=great_school_again
 1   column=school:name, timestamp=1443002311421, value=great_school 

正如预期的那样,它显示了旧价值和新价值。

Versioning is not enabled by default. So you have specify it while creating table.

create 'student',{NAME=>"personal",Versions=>5},'school'

Here versioning is enabled for column "personal" but not for column 'school'

This can be seen if you describe table

hbase(main):009:0> describe 'student'
Table student is ENABLED
student
COLUMN FAMILIES DESCRIPTION
{NAME => 'personal', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '5', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
{NAME => 'school', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}

For personal it shows VERSIONS => '5' For school it shows VERSIONS => '1'.

If table is already created it can be altered

alter 'student',NAME=>'school',VERSIONS =>3

hbase(main):011:0> describe 'student'
Table student is ENABLED
student
COLUMN FAMILIES DESCRIPTION
{NAME => 'personal', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '5', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
{NAME => 'school', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}

Not it shows VERSIONS => '3' For school as expected.

Put data into table. Enter multiple times in same cell. And then scan the table.

put 'student','1','personal:name','kaushik'
put 'student','1','personal:name','kaushik_again'
put 'student','1','school:name','great_school'
put 'student','1','school:name','great_school_again'

scan 'student',{VERSIONS=>10}
ROW  COLUMN+CELL
 1   column=personal:name, timestamp=1443002303208, value=kaushik_again
 1   column=personal:name, timestamp=1443002294049, value=kaushik
 1   column=school:name, timestamp=1443002320753, value=great_school_again
 1   column=school:name, timestamp=1443002311421, value=great_school 

As expected it is showing old value as well as new value.

烏雲後面有陽光 2024-12-27 10:33:58

可以使用 hbase shell 实现相同的效果:

get 'tablename', 'rowid', {COLUMN => 'cf:info', VERSIONS => 3}

上面将显示单元的最大 3 个版本(如果可用)。

The same can be achieved in hbase shell using:

get 'tablename', 'rowid', {COLUMN => 'cf:info', VERSIONS => 3}

The above will show the max 3 versions of the cell, if available.

影子是时光的心 2024-12-27 10:33:58

您可以指定扫描和获取获得的版本号,它将检索它们:

 HTable tbl = new HTable(tableName);
 Get q= new Get(Bytes.toBytes(key));
 q.setMaxVersions(numberOfVersionsYouWant);
 Result row= tbl.get(q);
 NavigableMap<byte[],NavigableMap<byte[],NavigableMap<Long,byte[]>>> allVersions=row.getMap();

You can specify the number of version you get for Scan and Get and it will retrieve them:

 HTable tbl = new HTable(tableName);
 Get q= new Get(Bytes.toBytes(key));
 q.setMaxVersions(numberOfVersionsYouWant);
 Result row= tbl.get(q);
 NavigableMap<byte[],NavigableMap<byte[],NavigableMap<Long,byte[]>>> allVersions=row.getMap();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文