2011-12-11 65 views

回答

7

您可以指定你的扫描版本的数量和获取,它会检索它们:用

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

同样可以在HBase的外壳来实现:

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

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

+0

有没有办法获得最低3版本? –

10

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

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 

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

相关问题