学习日志---hbase学习(最大版本查询)

在HBase中 一个row对应的相同的列只会有一行。使用scan 或get 得到都是最新的数据
如果我们对这某一row所对应的列进行了更改操作后,并不会多生成一条数据,不会像RDBMS一样
insert时多生成一条记录,在HBase中对同一条数据的修改或插入 都只是put操作,最终看到的都是
最新的数据,其它的数据在不同的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的个数会是2,因为把其隐藏起来了,所以在hbase命令行中也查询不到,只有这样查。