1
votes

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?

3

3 Answers

0
votes

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.

0
votes

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.

0
votes

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.