Hbase中hbse shell操作如下:
scan 'Test',{LIMIT=>10}
在java的api中可以通过过滤器来实现操,作如下:
Configuration HBASE_CONFIG = new Configuration();
HBASE_CONFIG.set("hbase.zookeeper.quorum", "XX.XX.XX.XX");
HBASE_CONFIG.set("hbase.zookeeper.property.clientPort", "2181");
hbaseConfig = new HBaseConfiguration(HBASE_CONFIG);
HBaseAdmin hAdmin = new HBaseAdmin(hbaseConfig);
System.out.println(hAdmin.tableExists(TABLE));
HTable table = new HTable(hbaseConfig, TABLE);
Scan scan = new Scan();
scan.setCaching(1);
Filter filter = new PageFilter(20); //
scan.setFilter(filter);
ResultScanner scanner = table.getScanner(scan);// 执行扫描查找
int num = 0;
Iterator<Result> res = scanner.iterator();// 返回查询遍历器
while (res.hasNext()) {
Result result = res.next();
num++;
System.out.println("key:" + new String(result.getRow()));
}
}
获取了前20条记录