org.apache.hadoop.hbase.filter
Class CompareFilter

java.lang.Object
  extended by org.apache.hadoop.hbase.filter.CompareFilter
All Implemented Interfaces:
Filter, org.apache.hadoop.io.Writable
Direct Known Subclasses:
QualifierFilter, RowFilter, ValueFilter

public abstract class CompareFilter
extends Object
implements Filter

This is a generic filter to be used to filter by comparison. It takes an operator (equal, greater, not equal, etc) and a byte [] comparator.

To filter by row key, use RowFilter.

To filter by column qualifier, use QualifierFilter.

To filter by value, use SingleColumnValueFilter.

These filters can be wrapped with SkipFilter and WhileMatchFilter to add more control.

Multiple filters can be combined using FilterList.


Nested Class Summary
static class CompareFilter.CompareOp
          Comparison operators.
 
Nested classes/interfaces inherited from interface org.apache.hadoop.hbase.filter.Filter
Filter.ReturnCode
 
Field Summary
protected  WritableByteArrayComparable comparator
           
protected  CompareFilter.CompareOp compareOp
           
 
Constructor Summary
CompareFilter()
          Writable constructor, do not use.
CompareFilter(CompareFilter.CompareOp compareOp, WritableByteArrayComparable comparator)
          Constructor.
 
Method Summary
protected  boolean doCompare(CompareFilter.CompareOp compareOp, WritableByteArrayComparable comparator, byte[] data, int offset, int length)
           
 boolean filterAllRemaining()
          If this returns true, the scan will terminate.
 Filter.ReturnCode filterKeyValue(KeyValue v)
          A way to filter based on the column family, column qualifier and/or the column value.
 boolean filterRow()
          Last chance to veto row based on previous Filter.filterKeyValue(KeyValue) calls.
 boolean filterRowKey(byte[] data, int offset, int length)
          Filters a row based on the row key.
 void readFields(DataInput in)
           
 void reset()
          Reset the state of the filter between rows.
 void write(DataOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

compareOp

protected CompareFilter.CompareOp compareOp

comparator

protected WritableByteArrayComparable comparator
Constructor Detail

CompareFilter

public CompareFilter()
Writable constructor, do not use.


CompareFilter

public CompareFilter(CompareFilter.CompareOp compareOp,
                     WritableByteArrayComparable comparator)
Constructor.

Parameters:
compareOp - the compare op for row matching
comparator - the comparator for row matching
Method Detail

reset

public void reset()
Description copied from interface: Filter
Reset the state of the filter between rows.

Specified by:
reset in interface Filter

filterKeyValue

public Filter.ReturnCode filterKeyValue(KeyValue v)
Description copied from interface: Filter
A way to filter based on the column family, column qualifier and/or the column value. Return code is described below. This allows filters to filter only certain number of columns, then terminate without matching ever column. If your filter returns ReturnCode.NEXT_ROW, it should return ReturnCode.NEXT_ROW until Filter.reset() is called just in case the caller calls for the next row.

Specified by:
filterKeyValue in interface Filter
Parameters:
v - the KeyValue in question
Returns:
code as described below
See Also:
Filter.ReturnCode

filterRowKey

public boolean filterRowKey(byte[] data,
                            int offset,
                            int length)
Description copied from interface: Filter
Filters a row based on the row key. If this returns true, the entire row will be excluded. If false, each KeyValue in the row will be passed to Filter.filterKeyValue(KeyValue) below.

Specified by:
filterRowKey in interface Filter
Parameters:
data - buffer containing row key
offset - offset into buffer where row key starts
length - length of the row key
Returns:
true, remove entire row, false, include the row (maybe).

filterRow

public boolean filterRow()
Description copied from interface: Filter
Last chance to veto row based on previous Filter.filterKeyValue(KeyValue) calls. The filter needs to retain state then return a particular value for this call if they wish to exclude a row if a certain column is missing (for example).

Specified by:
filterRow in interface Filter
Returns:
true to exclude row, false to include row.

filterAllRemaining

public boolean filterAllRemaining()
Description copied from interface: Filter
If this returns true, the scan will terminate.

Specified by:
filterAllRemaining in interface Filter
Returns:
true to end scan, false to continue.

doCompare

protected boolean doCompare(CompareFilter.CompareOp compareOp,
                            WritableByteArrayComparable comparator,
                            byte[] data,
                            int offset,
                            int length)

readFields

public void readFields(DataInput in)
                throws IOException
Specified by:
readFields in interface org.apache.hadoop.io.Writable
Throws:
IOException

write

public void write(DataOutput out)
           throws IOException
Specified by:
write in interface org.apache.hadoop.io.Writable
Throws:
IOException


Copyright © 2009 The Apache Software Foundation