hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From NNever <nnever...@gmail.com>
Subject How to define a custom filter to skip some amount of rows?
Date Tue, 14 Feb 2012 01:27:46 GMT
Hello~
In HBase-0.92.0rc4.
If I need to skip some amount of rows from the scan result, how can I
define a custom filter to do it?
Here is my solution:

*public class SkipFilter extends FilterBase{*
*    private long totalSkip = -1;*
*    private long currentSkip = 0;*
*    *
*    public SkipFilter(){}*
*
*
*    public SkipFilter(long totalSkip){*
*        this.totalSkip = totalSkip;*
*        currentSkip = 0;*
*    }*
*
*
*    // Only override this method*
*    public boolean filterRowKey(byte[] buffer, int offset, int length){*
*        if(currentSkip < totalSkip){*
*                currentSkip++;*
*                return true;*
*        }else{*
*                return false;*
*        }*
*    }*
*
*
*    ...readFileds...*
*    ...write...*
*}*

And used like this:

*Scan scan = new Scan();*
*scan.setStartRow(xxx);*
*scan.setEndRow(xxx);*
*Filter someFilter = new XXXFilter();*
*Filter skipFilter = new SkipFilter(100);*
*scan.setFilter(new FilterList(someFilter,...,skipFilter));*
*...doScan....*

*
*
Well, it works fine.  I scan some table, and the result can jump the first
100 rows, start from the 101th suitable row.
But when I delete some row from this table, tragedy accure!! *The
filter.filterRowKey can meet the deleted row*(I have post a mail before to
discribe this).
So if I try to skip the first 100 undeleted row, I user SkipFilter(100),
but infact it can only filter out 99 rows.
If I use this to do Paging, then at the second page I may meet the same row
from first page.

Can someone give me some suggestions on it or how to design a better
SkipFilter to suit my need?
Thanks!

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message