簡體   English   中英

從hbase行檢索時間戳

[英]Retrieving timestamp from hbase row

使用Hbase API(Get / Put)或HBQL API,是否可以檢索特定列的時間戳?

假設您的客戶端已配置並且您有一個表設置。 執行get返回Result

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

結果由KeyValue支持。 KeyValues包含時間戳。 您可以使用list()獲取KeyValues列表,也可以使用raw()獲取數組。 KeyValue具有get timestamp方法。

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

是一個很好的風格

我認為以下會更好:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM