Support Questions

Find answers, ask questions, and share your expertise

How to get the last key/value of rowpefix filter in hbase ?

avatar
Contributor

Hello ,

My hbase table rowkey are in following format:

vin1ts1

vin1ts2

vin1ts3

vin2ts1

vin2ts2

vin2ts3

vin2ts4

etc....

I would like to get the last available key of each ROWPREFIX , where ROWPREFIX ={VIN1, VIN2, VIN3,...}

Example: for RowPrefix= VIN1, It should return "Rowkey=vin1ts3" & its values.

--------

I am trying to use the reverse scan feature as below:

Scan scan = new Scan();

scan.setCaching(1)

FilterList allFilters = new FilterList(FilterList.Operator.MUST_PASS_ALL);

allFilters.addFilter(new PrefixFilter(Bytes.toBytes(prefixFilterValue)));

scan.setFilter(allFilters);

scan.setReversed(true); //Read the latest available key and value

scan.setMaxResultSize(1);

ResultScanner scanner = tblConn.getScanner(scan);

Result result = scanner.next();

LOGGER.log(Level.INFO, "Latest Key " + Bytes.toString(result.getRow()));

scanner.close();

-----------

Above code works but takes around ~40 second to retrieve the target rowkey.

Is there any better approach to get the same since 40 second is not sufficing our business condition ?

Or do I need to set any scan property to reduce the scanner time ?

Any pointers would be appreciated..

CLUSER INFO:

HDP:

HDP-2.5.5.0

hbase -version:

Version 1.1.2.2.5.5.0-157, r002c801447187c620c26ffc130ff17a9b0a62ac1, Fri Apr 21 01:13:10 UTC 2017

Regards,

Revan

4 REPLIES 4

avatar
Contributor

what is your input? Are you trying to access all rows with latest TS or specific record based on input?

avatar
Contributor

@Nikhil Silsarma Specific records (On Rowprefix value)

avatar
Contributor

try adding these below to define range

scan.setStartRow(org.apache.hadoop.hbase.util.Bytes.toBytesBinary(prefixFilterValue));

scan.setEndRow(org.apache.hadoop.hbase.util.Bytes.toBytesBinary(prefixFilterValue.concat(String.valueOf(Long.MAX_VALUE))));

avatar
Contributor

@Nikhil Silsarma

"scan.setEndRow" API is not available with my hbase version= -version: "Version 1.1.2.2.5.5.0-157"

Will It work with "scan.setStopRow()" API ?


Let me try and will update ..