Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command like SQL LIMIT in HBase

Tags:

nosql

hbase

Does HBase have any command that works like SQL LIMIT query?

I can do it by setStart and setEnd, but I do not want to iterate all rows.

like image 811
Mohammad Avatar asked Dec 22 '12 12:12

Mohammad


People also ask

Which of the following command operate on tables in HBase?

These are the commands that operate on the tables in HBase. create - Creates a table. list - Lists all the tables in HBase. disable - Disables a table.

Which command is used to show the current HBase user?

whoami. This command “whoami” is used to return the current HBase user information from the HBase cluster.


2 Answers

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
like image 143
th30z Avatar answered Oct 10 '22 20:10

th30z


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

like image 35
mirsik Avatar answered Oct 10 '22 18:10

mirsik