【问题标题】:how to get the row key from hbase scan result如何从 hbase 扫描结果中获取行键
【发布时间】:2012-08-02 23:14:06
【问题描述】:

逐行扫描 hbase 表时,如何获取行键?这是我的代码:

for (Result rr : scanner) {
   System.out.println(rr);
}

有没有像 getKey() 这样的方法可以使用?谢谢。

【问题讨论】:

    标签: java hbase


    【解决方案1】:

    如果您想要字符串格式的行键,请使用getRowBytes.toString 方法:

    for (Result rr : scanner) {
       String key = Bytes.toString(rr.getRow())
    }
    

    HBase API - Result object

    getRow() 检索与创建此结果的行对应的行键的方法。

    【讨论】:

    • 我在方法列表中看到了 getRow(),这是检索 RowKey 的唯一候选者。只是好奇,为什么他们决定将其命名为 getRow() 而不是 getRowKey()?
    • 这个答案正确吗?我想知道如果是这样为什么不被接受。
    • @Mahdi 这个答案是正确的。根据文档“检索与创建此结果的行相对应的行键的方法。”(hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/…)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-28
    • 2012-10-18
    • 1970-01-01
    相关资源
    最近更新 更多