Question

Using Hbase API (Get/Put) or HBQL API, is it possible to retrieve timestamp of a particular column?

Was it helpful?

Solution

Assuming your client is configured and you have a table setup. Doing a get returns a Result

Get get = new Get(Bytes.toBytes("row_key"));
Result result_foo = table.get(get);

A Result is backed by a KeyValue. KeyValues contain the timestamps. You can get either a list of KeyValues with list() or get an array with raw(). A KeyValue has a get timestamp method.

result_foo.raw()[0].getTimestamp()

OTHER TIPS

result_foo.rawCells()(0).getTimestamp

is a good style

I think the follow will be better:

KeyValue kv = result.getColumnLatest(family, qualifier);
String status = Bytes.toString(kv.getValue());
Long timestamp = kv.getTimestamp();

since Result#getValue(family, qualifier) is implemented as

public byte[] getValue(byte[] family, byte[] qualifier) {
        KeyValue kv = this.getColumnLatest(family, qualifier);
        return kv == null ? null : kv.getValue();
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top