2011-12-11 63 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 

正如預期的那樣,它顯示出舊的價值以及新的價值。

相關問題