user3570620
user3570620

Reputation: 359

HBASE Record limit in scan api

Is there any java api to limit the number of scanned records after using start and stop rows? Is pagefilter an option?

Upvotes: 1

Views: 7672

Answers (4)

Y.H.
Y.H.

Reputation: 2847

This answer applies if you want to get a single row only

If you're using an older version of HBase where setLimit is not available, you could use stopRow instead giving it the same value as startRow and adding a trailing byte set to zero to make it inclusive, from the documentation:

Note: In order to make stopRow inclusive add a trailing 0 byte

Here is an example:

    byte[] startRow = new byte[] { (byte)0xab, (byte)0xac};
    byte[] stopRow = new byte[startRow.length + 1];
    Array.copy(startRow, 0, stopRow, 0, startRow.length);
    stopRow[stopRow.length - 1] = 0; // inclusive
    Scan scan = new Scan().setStartRow(startRow).setStopRow(stopRow);
    

Upvotes: 0

fudy
fudy

Reputation: 1629

use scan.setLimit(int) method

https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/Scan.html#setLimit-int-

Set the limit of rows for this scan. We will terminate the scan if the number of returned rows reaches this value. This condition will be tested at last, after all other conditions such as stopRow, filter, etc.

Upvotes: 1

Anil Gupta
Anil Gupta

Reputation: 1126

http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/Scan.html#setCaching(int) might be able to help you. setCaching() is used to define how many results HBase should return in one RPC call.

Upvotes: 0

Oussama Jilal
Oussama Jilal

Reputation: 7739

Did you try to use the setMaxResultSize() ?

PageFilter may not give the expected results, the doc says:

this filter cannot guarantee that the number of results returned to a client are <= page size. This is because the filter is applied separately on different region servers. It does however optimize the scan of individual HRegions by making sure that the page size is never exceeded locally.

Upvotes: 1

Related Questions