【问题标题】:Retrieving timestamp from hbase row从 hbase 行中检索时间戳
【发布时间】:2011-11-30 05:58:00
【问题描述】:

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

【问题讨论】:

    标签: java hbase flume


    【解决方案1】:

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

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

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

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

    【讨论】:

    • [0] 是否表示 hbase 中的第一列?有没有办法获得特定指定列名的时间戳?
    • 时间已经够长了,我不记得那些文档中的任何细节了。从那以后情况可能发生了变化。最好的办法是为您的 hbase 设置启动一个控制台并四处寻找。
    【解决方案2】:

    我认为以下会更好:

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

    【讨论】:

      【解决方案3】:

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

      在 Result 对象上使用getColumnLatestCell 方法,然后像这样调用getTimestamp 方法:

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

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

      【讨论】:

        【解决方案4】:
        result_foo.rawCells()(0).getTimestamp
        

        风格不错

        【讨论】:

        • 索引周围仍然需要方括号,例如rawCells()[0]
        猜你喜欢
        • 2015-07-27
        • 2012-05-07
        • 1970-01-01
        • 2022-11-20
        • 2020-04-08
        • 2012-01-27
        • 1970-01-01
        • 2013-06-20
        • 1970-01-01
        相关资源
        最近更新 更多