Pagination with Hbase

Pagination with Hbase

Pagefilter is use for pagination and it controls how many row per page should be returned.

Filter filter =new PageFilter(15);

Filter filter = new PageFilter(15);

Hbase pagination always work in forward direction, there are no way to go reverse or in backward direction.

suppose you need to implement functionality at UI pagination table and it should have next/forward and back/backward feature.

Forward option easily implemented using PageFilter but for backward, no solution. e.g. you need to get the rows(20) from end key to most recent and going backward. eg. backward get all records 1000 – 980.
Unless your rows are predictable (you know how many rows between row key 0 and row key 2^32) reverse scanning won’t even matter but If the rows are unpredictable, you would always have to scan the entire set to find out how many pages there and get the particular range start and stop row key.

I worked on similar use case, alternate solutions can be if your dataset is very huge-

Secondary index table-

each insert into main table, create a entry into secondary table that’s sorted in reverse order. whenever request comes for scan in backward, scan the reverse/ index table for number of rows then use the returned start and stop row key to query on actual table.

if required, maintain the last accessed extra column for clean up job that clean up the table periodically.
whenever request comes for scan in backward, get the start key from pagination table using ‘search criteria’+numberOfRecords and pageNumber, then search on actual table. each requests should contains pagination bean.