简体   繁体   English

如何在Hbase中获得给定行键的一部分的所有行

[英]How to get all the rows given a part of the row key in Hbase

I have the following table structure in Hbase: 我在Hbase中具有以下表结构:

Row               column+cell

Mary_Ann_05/10/2013 column=cf:verified, timestamp=234454454,value=2,2013-02-12  
Mary_Ann_06/10/2013 column=cf:verified, timestamp=2345454454,value=3,2013-02-12 
Mary_Ann_07/10/2013 column=cf:verified, timestamp=2345454522454,value=4,2013-02-12 
Mary_Ann_08/10/2013 column=cf:verified, timestamp=23433333454,value=1,2013-12-12 

I want to retrieve all the records that start with Mary_Ann using java. 我想使用Java检索以Mary_Ann开头的所有记录。 How do I do that? 我怎么做?

You could achieve that using PrefixFilter . 您可以使用PrefixFilter来实现。 Given a prefix, specified when you instantiate the filter instance, all rows that match this prefix are returned to the client. 给定一个实例化过滤器实例时指定的前缀,与此前缀匹配的所有行都将返回给客户端。 The constructor is : public PrefixFilter(byte[] prefix) 构造函数为: public PrefixFilter(byte[] prefix)

Usage : 用法:

Filter filter = new PrefixFilter(Bytes.toBytes("Mary_Ann"));
Scan scan = new Scan();
scan.setFilter(filter);
ResultScanner scanner = table.getScanner(scan);
for (Result result : scanner) {
     for (KeyValue kv : result.raw()) {
        System.out.println("KV: " + kv + ", Value: " +
        Bytes.toString(kv.getValue()));
     }
}
scanner.close();

HTH 高温超导

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM