温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-03-01 03:39:11 来源:网络 阅读:530 作者:wukong0716 栏目:关系型数据库

在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命令行中也查询不到,只有这样查。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI