http://jiajun.iteye.com/blog/945358 參詳-》源碼實現 html
HBase建立表未指定版本 [建表時默認的VERSION是1.] apache
create 'mytable', {NAME => 'colfam1'} api
向'mytable'中添加三條數據: oop
put 'mytable','001','colfam1','1@' this
put 'mytable','001','colfam1','1%' spa
put 'mytable','001','colfam1','1&' .net
put 'mytable','001','colfam1','1*'
code
scan 'mytable' 中的數據【默認只能查看最新的數據,想查看多個版本須要指定下】 orm
看到的最後一條記錄。 htm
查找時指定了版本,仍是看到最後一條記錄。雖然加了VERSIONS,但get的結果是1條;這就是由於建表時默認的VERSION是1.
能夠修改VERSIONS:alter 'member',{NAME=>'info','VERSIONS'=>2}
分析:與建表時指定的保留版本數有關係
HBase建立表指定版本:(加了VERSIONS=>3,就能夠查到歷史的數據了,可是必須再建立表的時候加上VERSIONS,不然無效)
create 'mytable', {NAME => 'colfam1', VERSIONS => 5,MIN_VERSIONS => '3'}
put 'mytable','001','colfam1','1@'
put 'mytable','001','colfam1','1%'
put 'mytable','001','colfam1','jhl'
put 'mytable','001','colfam1','hjf'
get 'mytable','001',{COLUMN => 'colfam1',VERSIONS => 3}
get 'mytable','001',{COLUMN => 'colfam1',VERSIONS => 5}
總結:1.若想保留表的列族的歷史記錄:就要在當前列上指定版本信息
{COLUMN => 'colfam1',VERSIONS => 5}
2.scan table 始終是掃描到表的每一行的最大版本的那條記錄。
參詳api解釋:
Gets實在Scan的基礎上實現的。能夠詳細參見下面的討論 Get 一樣能夠用 Scan來描述.
默認狀況下,若是你沒有指定版本,當你使用Get操做的時候,會返回最近版本的Cell(該Cell多是最新寫入的,但不能保證)。默認的操做能夠這樣修改:
若是想要返回返回兩個以上的把版本,參見Get.setMaxVersions()
若是想要返回的版本不僅是最近的,參見 Get.setTimeRange()
要向查詢的最新版本要小於或等於給定的這個值,這就意味着給定的'最近'的值能夠是某一個時間點。能夠使用0到你想要的時間來設置,還要把max versions設置爲1.
下面的Get操做會只得到最新的一個版本。
Get get = new Get(Bytes.toBytes("row1")); Result r = htable.get(get); byte[] b = r.getValue(Bytes.toBytes("cf"), Bytes.toBytes("attr")); // returns current version of value
下面的Get操做會得到最近的3個版本。
Get get = new Get(Bytes.toBytes("row1")); get.setMaxVersions(3); // will return last 3 versions of row Result r = htable.get(get); byte[] b = r.getValue(Bytes.toBytes("cf"), Bytes.toBytes("attr")); // returns current version of value List<KeyValue> kv = r.getColumn(Bytes.toBytes("cf"), Bytes.toBytes("attr")); // returns all versions of this column
http://blog.csdn.net/wind520/article/details/39344805 (API實現 )