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

时间:2011-12-11 17:45:23

标签: hbase

众所周知,hbase具有一个特定行和特定列可以按时间戳记录最近更改值的功能。 所以我的问题是,如何使用任何HBase命令列出所有更改的值?我google了很多,但没有找到任何有用的链接。

3 个答案:

答案 0 :(得分:14)

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

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

此处为列"个人"启用版本控制。但不适用于专栏'学校

如果您描述表

,可以看到这一点
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'}

对于personal,它显示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' school

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

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 

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

答案 1 :(得分:10)

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

 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();

答案 2 :(得分:10)

使用以下命令可以在hbase shell中实现:

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

以上将显示单元格的最多3个版本(如果有)。