Store multiple versions in hbase row with the same family: qualifier but different timestamps.

牧云@^-^@ 提交于 2019-12-11 08:24:36

问题


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?


回答1:


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.




回答2:


No. You can only have one value in a column for a given rowkey. If you want another value, you'll have to give it its own rowkey, or put it in a different column.




回答3:


You're in wrong.

Hbase by default has 3 versions in a cell.It means that if you save and update 3 times in a cell hbase stores them with time stamps in 3 versions. You cannot store in a cell with time stamp.

If you want another value, you'll have to put it in a different column family or different column.



来源:https://stackoverflow.com/questions/22587037/store-multiple-versions-in-hbase-row-with-the-same-family-qualifier-but-differe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!