从 hbase 行检索时间戳

发布于 2024-12-18 14:39:50 字数 55 浏览 5 评论 0原文

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦回旧景 2024-12-25 14:39:50

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

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

结果是由 KeyValue 支持。 KeyValues 包含时间戳。您可以使用 list() 获取键值列表,也可以使用 raw() 获取数组。 KeyValue 有一个获取时间戳方法。

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

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()
咆哮 2024-12-25 14:39:50

@codingFoo 的答案假设所有单元格的所有时间戳都相同,但 op 的问题是针对特定列的。在这方面,类似于@peibin wang的答案,如果您想要专栏的最后一个时间戳,我会建议以下内容:

使用 getColumnLatestCell 对 Result 对象进行方法,然后调用getTimestamp 方法如下:

Result res = ...
res.getColumnLatestCell(Bytes.toBytes("column_family"), Bytes.toBytes("column_qualifier")).getTimestamp();

如果您想访问特定时间戳,您可以使用 getColumnCells 返回指定列的所有单元格,但随后您必须在带有 < 的单元格之间进行选择代码>获取(int index) 然后调用 getTimestamp()

@codingFoo's answer assumes all timestamps are the same for all cells, but op's question was for a specific column. In that respect, similar to @peibin wang's answer, I would propose the following if you would like the last timestamp for your column:

Use the getColumnLatestCell method on your Result object, and then call the getTimestamp method like so:

Result res = ...
res.getColumnLatestCell(Bytes.toBytes("column_family"), Bytes.toBytes("column_qualifier")).getTimestamp();

If you want access to a specific timestamp you could use the getColumnCells which returns all cells for a specified column, but then you will have to choose between the cells with a get(int index) and then call getTimestamp()

大姐,你呐 2024-12-25 14:39:50
result_foo.rawCells()(0).getTimestamp

是一个很好的风格

result_foo.rawCells()(0).getTimestamp

is a good style

浅语花开 2024-12-25 14:39:50

我认为以下会更好:

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();
    }

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();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文