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

===============>>#1 票数: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 

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

===============>>#2 票数:11 已采纳

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

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

===============>>#3 票数:10

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

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

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

  ask by mlzboy translate from so

未解决问题?本站智能推荐:

关注微信公众号