有人能告诉我,如何列出hbase表中的所有行键?
答案 0 :(得分:21)
HBase shell可用于列出所有行键:
count 'table_name', { INTERVAL => 1 }
答案 1 :(得分:13)
这应该快得多(FirstKeyOnlyFilter在服务器上运行并在将结果发送到客户端之前删除所有列数据):
Configuration conf = HBaseConfiguration.create();
HTable table = new HTable(conf, tableName.getBytes());
System.out.println("scanning full table:");
Scan scan = new Scan();
scan.setFilter(new FirstKeyOnlyFilter());
ResultScanner scanner = table.getScanner(scan);
for (Result rr : scanner) {
byte[] key == rr.getRow();
...
}
答案 2 :(得分:5)
Configuration conf = HBaseConfiguration.create();
HTable table = new HTable(conf, tableName.getBytes());
System.out.println("scanning full table:");
ResultScanner scanner = table.getScanner(new Scan());
for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
byte[] key == rr.getRow();
...
}
答案 3 :(得分:2)
执行只需要行键的表扫描(无族,限定符,值或时间戳)时,使用setFilter将带有MUST_PASS_ALL运算符的FilterList添加到扫描程序。筛选器列表应包括FirstKeyOnlyFilter和KeyOnlyFilter。使用此过滤器组合将导致RegionServer从磁盘读取单个值的最坏情况和单个行到客户端的最小网络流量。
答案 4 :(得分:2)
使用Result类的getRow方法。它的描述说:
检索与行对应的行键的方法 该结果已创建。
假设table
是您的hbase表并且您已连接到HBase实例,那么您需要做的就是:
Scan scan = new Scan();
ResultScanner rscanner = table.getScanner(scan);
for(Result r : rscanner){
//r is the result object that contains the row
//do something
System.out.println(Bytes.toString(r.getRow())); //doing something
}
我知道这已经从Java API的角度来回答了,但更多的细节从未伤害过任何人。
答案 5 :(得分:1)
似乎你想在PHP中使用HBase thrift客户端。下面是一个示例代码,您可以获取HBase中的所有数据并获取其行键。
<? $_SERVER['PHP_ROOT'] = realpath(dirname(__FILE__).'/..');
require_once $_SERVER['PHP_ROOT'].'/flib/__flib.php';
flib_init(FLIB_CONTEXT_SCRIPT);
require_module('storage/hbase');
$hbase = new HBase('<server_name_running_thrift_server>', <port on which thrift server is running>);
$hbase->open();
$client = $hbase->getClient();
$result = $client->scannerOpenWithFilterString('table_name', "(PrefixFilter ('row2') AND (QualifierFilter (>=, 'binary:xyz'))) AND (TimestampsFilter ( 123, 456))");
$to_print = $client->scannerGetList($result,1);
while ($to_print) {
print_r($to_print);
$to_print = $client->scannerGetList($result,1);
}
$client->scannerClose($result);
?>