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条记录

本文详细阐述了在HBase中使用hbase shell与Java API进行数据操作的方法,包括如何通过过滤器在Java中实现类似shell的操作,并提供了一个实际的代码示例,展示如何获取前20条记录。
1453

被折叠的 条评论
为什么被折叠?



