将hbase行中的多个版本存储在同一系列中:限定符但不同的时间戳。 [英] Store multiple versions in hbase row with the same family: qualifier but different timestamps.

查看:233
本文介绍了将hbase行中的多个版本存储在同一系列中:限定符但不同的时间戳。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想存储具有相同系列:限定符但不同值和时间戳的行的多个版本。

  Put put = new Put(Bytes.toBytes(key)); 
put.add(family,qualifier,timestamp0,value0);
put.add(family,qualifier,timestamp1,value1);
table.put(put);

但是,只有其中一个具有较高时间戳的将存储在表中。这个问题不是因为MaxVersions。有没有什么办法可以让hbase存储这两个版本?

我写了一个测试,没关系。
请检查您的配置。

  byte [] rowKey = Bytes.toBytes(allen_test_row); 
Put put = new Put(rowKey);
put.add(ColumnFamilyName,QName1,1000,Bytes.toBytes(a));
put.add(ColumnFamilyName,QName1,2000,Bytes.toBytes(b));
table.put(put);

Get get = new Get(rowKey);
get.setMaxVersions(10);
结果结果= table.get(get);
KeyValue [] keyValues = result.raw();
Assert.assertEquals(2,keyValues.length);
//有a和b两个。
Assert.assertEquals('a'+'b',keyValues [0] .getValue()[0]
+ keyValues [1] .getValue()[0]);

何时从hbase获取数据?
是否指定了maxversion?



BTW
您可以使用 https://github.com/zhang-xzhi/simplehbase 到一个rowkey - 许多DO映射。


I want to store multiple versions of a row which has the same family: qualifier but different value and timestamps.

    Put put = new Put(Bytes.toBytes(key));
    put.add(family, qualifier,timestamp0, value0);
    put.add(family, qualifier,timestamp1, value1);
    table.put(put);

However, only one of them which had the higher timestamp will be stored in the table. The issue is not because of MaxVersions. Is there any way I could have hbase to store both versions?

解决方案

I wrote a test, and it is ok. pls check your config.

    byte[] rowKey = Bytes.toBytes("allen_test_row");
    Put put = new Put(rowKey);
    put.add(ColumnFamilyName, QName1, 1000, Bytes.toBytes("a"));
    put.add(ColumnFamilyName, QName1, 2000, Bytes.toBytes("b"));
    table.put(put);

    Get get = new Get(rowKey);
    get.setMaxVersions(10);
    Result result = table.get(get);
    KeyValue[] keyValues = result.raw();
    Assert.assertEquals(2, keyValues.length);
    //have a and b both.
    Assert.assertEquals('a' + 'b', keyValues[0].getValue()[0]
            + keyValues[1].getValue()[0]);

when you get the data from hbase? did you specify the maxversion?

BTW you can use https://github.com/zhang-xzhi/simplehbase to one rowkey - many DO mapping.

这篇关于将hbase行中的多个版本存储在同一系列中:限定符但不同的时间戳。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆