从hbase行检索时间戳

swvgeqrz  于 2021-06-04  发布在  Flume
关注(0)|答案(3)|浏览(303)

使用hbase api(get/put)或hbqlapi,是否可以检索特定列的时间戳?

55ooxyrt

55ooxyrt1#

我认为以下几点会更好:

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

因为result#getvalue(family,qualifier)实现为

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

nhhxz33t2#

假设您的客户机已配置,并且您有一个表设置。执行get返回一个结果

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

结果由keyvalue支持。键值包含时间戳。可以使用list()获取keyvalues列表,也可以使用raw()获取数组。keyvalue具有get timestamp方法。

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

slhcrj9b3#

result_foo.rawCells()(0).getTimestamp

是一种好的风格

相关问题