溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

學習日志---hbase學習(最大版本查詢)

發(fā)布時間:2020-03-01 03:39:11 來源:網(wǎng)絡 閱讀:543 作者:wukong0716 欄目:關系型數(shù)據(jù)庫

在HBase中 一個row對應的相同的列只會有一行。使用scan 或get 得到都是最新的數(shù)據(jù)
如果我們對這某一row所對應的列進行了更改操作后,并不會多生成一條數(shù)據(jù),不會像RDBMS一樣
insert時多生成一條記錄,在HBase中對同一條數(shù)據(jù)的修改或插入 都只是put操作,最終看到的都是
最新的數(shù)據(jù),其它的數(shù)據(jù)在不同的version中保存,就像隱藏的東西一樣

那么如何才能看到這些隱藏version的值呢

            Get get = new Get(startRow);
            get.setMaxVersions();
            Result result = table.get(get);
             List<KeyValue> list = result.list(); 
              for(final KeyValue v:list){
                  logger.info("value: "+ v+ " str: "+Bytes.toString(v.getValue()));
              }
加入setMaxVersions()方法就可以把所有的版本都取出來了


實例代碼:

@Test
	public void test4() throws Exception
	{
		Configuration config = HBaseConfiguration.create();  
		config.set("hbase.zookeeper.quorum", "hadoop1,hadoop2,hadoop3");
		HTable hTable = new HTable(config, "t_xuanxuan");
		Get get = new Get("29129101029_1444038378601".getBytes());
                get.setMaxVersions();
                //這里設置的是2
                Result result = hTable.get(get);
                System.out.println(result.size());
                List<KeyValue> list = result.list(); 
                for(final KeyValue v:list){
                 System.out.println("value: "+ v+ " str: "+Bytes.toString(v.getValue()));
                }
	}

result的個數(shù)會是2,因為把其隱藏起來了,所以在hbase命令行中也查詢不到,只有這樣查。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI