Return-Path: X-Original-To: apmail-hbase-user-archive@www.apache.org Delivered-To: apmail-hbase-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B2B359D6A for ; Fri, 17 Feb 2012 19:30:54 +0000 (UTC) Received: (qmail 91856 invoked by uid 500); 17 Feb 2012 19:30:53 -0000 Delivered-To: apmail-hbase-user-archive@hbase.apache.org Received: (qmail 91814 invoked by uid 500); 17 Feb 2012 19:30:53 -0000 Mailing-List: contact user-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@hbase.apache.org Delivered-To: mailing list user@hbase.apache.org Received: (qmail 91806 invoked by uid 99); 17 Feb 2012 19:30:53 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Feb 2012 19:30:53 +0000 X-ASF-Spam-Status: No, hits=-0.5 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of dlieu.7@gmail.com designates 209.85.220.169 as permitted sender) Received: from [209.85.220.169] (HELO mail-vx0-f169.google.com) (209.85.220.169) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Feb 2012 19:30:45 +0000 Received: by vcbf13 with SMTP id f13so3608283vcb.14 for ; Fri, 17 Feb 2012 11:30:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=dCl3q5cgocW8aUVhCdbXCAdI9YQ5i8qY1gq/X8HgXrI=; b=WH5uIjSDoBwFNaMUh7NvOZAi4veuqW74//a3mYX07qlaiuG93SxGB29dscIcByHZg3 kKIjz7c4fXwTAqkrnS4LvNRhCQ86hEC+jsqeF4DoE3mw/HFe9xuZwbBlSLQKXwwaTI/Z zXJJQSHWEO7yu8GOwNlf/IofNrwTP3PNuf4DI= MIME-Version: 1.0 Received: by 10.220.108.70 with SMTP id e6mr4856378vcp.74.1329507024604; Fri, 17 Feb 2012 11:30:24 -0800 (PST) Received: by 10.52.29.243 with HTTP; Fri, 17 Feb 2012 11:30:24 -0800 (PST) In-Reply-To: References: Date: Fri, 17 Feb 2012 11:30:24 -0800 Message-ID: Subject: Re: How to define a custom filter to skip some amount of rows? From: Dmitriy Lyubimov To: user@hbase.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Filters support re-seek functionality. Hint can be given on the point of re-seek. Re-seek can be applied to either columns or rows (basically, hint is the new target of re-seek as key-value). You can find details in the hbase book (and perhaps somewhere online, too). -d On Mon, Feb 13, 2012 at 5:27 PM, NNever wrote: > 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{* > * =A0 =A0private long totalSkip =3D -1;* > * =A0 =A0private long currentSkip =3D 0;* > * =A0 =A0* > * =A0 =A0public SkipFilter(){}* > * > * > * =A0 =A0public SkipFilter(long totalSkip){* > * =A0 =A0 =A0 =A0this.totalSkip =3D totalSkip;* > * =A0 =A0 =A0 =A0currentSkip =3D 0;* > * =A0 =A0}* > * > * > * =A0 =A0// Only override this method* > * =A0 =A0public boolean filterRowKey(byte[] buffer, int offset, int lengt= h){* > * =A0 =A0 =A0 =A0if(currentSkip < totalSkip){* > * =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0currentSkip++;* > * =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return true;* > * =A0 =A0 =A0 =A0}else{* > * =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return false;* > * =A0 =A0 =A0 =A0}* > * =A0 =A0}* > * > * > * =A0 =A0...readFileds...* > * =A0 =A0...write...* > *}* > > And used like this: > > *Scan scan =3D new Scan();* > *scan.setStartRow(xxx);* > *scan.setEndRow(xxx);* > *Filter someFilter =3D new XXXFilter();* > *Filter skipFilter =3D new SkipFilter(100);* > *scan.setFilter(new FilterList(someFilter,...,skipFilter));* > *...doScan....* > > * > * > Well, it works fine. =A0I scan some table, and the result can jump the fi= rst > 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 t= o > 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 r= ow > from first page. > > Can someone give me some suggestions on it or how to design a better > SkipFilter to suit my need? > Thanks!