Command like SQL LIMIT in HBase
Solution 1:
From the HBase shell you can use LIMIT:
hbase> scan 'test-table', {'LIMIT' => 5}
From the Java API you can use Scan.setMaxResultSize(N)
or scan.setMaxResultsPerColumnFamily(N)
.
- HBase API docs - Scan.setMaxResultSize
- HBase API docs - Scan.setMaxResultsPerColumnFamily
Solution 2:
There is a filter called PageFilter. Its meant for this purpose.
Scan scan = new Scan(Bytes.toBytes("smith-"));
scan.addColumn(Bytes.toBytes("personal"), Bytes.toBytes("givenName"));
scan.addColumn(Bytes.toBytes("contactinfo"), Bytes.toBytes("email"));
scan.setFilter(new PageFilter(25));
ResultScanner scanner = table.getScanner(scan);
for (Result result : scanner) {
// ...
}
http://java.dzone.com/articles/handling-big-data-hbase-part-4