扫描Hbase以获取特定的rowkey

时间:2013-05-14 08:36:36

标签: hbase

我想从特定的Rowkey中获取Hbase表中的所有列。

eg:
 Rowkey starts from 123456
 Rowkey ends with 123466

so i want to fetch programatically (In java) all columns  within this rowkeym only.

1 个答案:

答案 0 :(得分:1)

这很直截了当。你有没有尝试过什么?反正,

Configuration conf = HbaseConfiguration.create();
HTable table = new HTable(conf, "tablename");
Scan scan = new Scan();
scan.setStartRow(Bytes.toBytes("123456"));
scan.setStopRow(Bytes.toBytes("123456"));
ResultScanner rs = table.getScanner();
for (Result result : scanner) {
     for (KeyValue kv : result.raw()) {
        System.out.println("KV: " + kv + ", Value: " +
        Bytes.toString(kv.getValue()));
     }
}
scanner.close();