简体   繁体   English

从hbase行检索时间戳

[英]Retrieving timestamp from hbase row

使用Hbase API(Get / Put)或HBQL API,是否可以检索特定列的时间戳?

Assuming your client is configured and you have a table setup. 假设您的客户端已配置并且您有一个表设置。 Doing a get returns a Result 执行get返回Result

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

A Result is backed by a KeyValue . 结果由KeyValue支持。 KeyValues contain the timestamps. KeyValues包含时间戳。 You can get either a list of KeyValues with list() or get an array with raw(). 您可以使用list()获取KeyValues列表,也可以使用raw()获取数组。 A KeyValue has a get timestamp method. KeyValue具有get timestamp方法。

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

是一个很好的风格

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 因为Result#getValue(family,qualifier)实现为

public byte[] getValue(byte[] family, byte[] qualifier) {
        KeyValue kv = this.getColumnLatest(family, qualifier);
        return kv == null ? null : kv.getValue();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM