org.apache.hadoop.hbase.filter
Class ColumnValueFilter

java.lang.Object
  extended by org.apache.hadoop.hbase.filter.ColumnValueFilter
All Implemented Interfaces:
RowFilterInterface, org.apache.hadoop.io.Writable

public class ColumnValueFilter
extends Object
implements RowFilterInterface

This filter is used to filter based on the value of a given column. It takes an operator (equal, greater, not equal, etc) and either a byte [] value or a byte [] comparator. If we have a byte [] value then we just do a lexicographic compare. If this is not sufficient (eg you want to deserialize a long and then compare it to a fixed long value, then you can pass in your own comparator instead.


Nested Class Summary
static class ColumnValueFilter.CompareOp
          Comparison operators.
 
Constructor Summary
ColumnValueFilter(byte[] columnName, ColumnValueFilter.CompareOp compareOp, byte[] value)
          Constructor.
ColumnValueFilter(byte[] columnName, ColumnValueFilter.CompareOp compareOp, byte[] value, boolean filterIfColumnMissing)
          Constructor.
ColumnValueFilter(byte[] columnName, ColumnValueFilter.CompareOp compareOp, WritableByteArrayComparable comparator)
          Constructor.
ColumnValueFilter(byte[] columnName, ColumnValueFilter.CompareOp compareOp, WritableByteArrayComparable comparator, boolean filterIfColumnMissing)
          Constructor.
 
Method Summary
 boolean filterAllRemaining()
          Determines if the filter has decided that all remaining results should be filtered (skipped).
 boolean filterColumn(byte[] rowKey, byte[] colKey, byte[] data)
          Filters on row key, column name, and column value.
 boolean filterRow(SortedMap<byte[],Cell> columns)
          Filter on the fully assembled row.
 boolean filterRowKey(byte[] rowKey)
          Filters on just a row key.
 boolean processAlways()
          Returns whether or not the filter should always be processed in any filtering call.
 void readFields(DataInput in)
           
 void reset()
          Resets the state of the filter.
 void rowProcessed(boolean filtered, byte[] key)
          Called to let filter know the final decision (to pass or filter) on a given row.
 void validate(byte[][] columns)
          Validates that this filter applies only to a subset of the given columns.
 void write(DataOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ColumnValueFilter

public ColumnValueFilter(byte[] columnName,
                         ColumnValueFilter.CompareOp compareOp,
                         byte[] value)
Constructor.

Parameters:
columnName - name of column
compareOp - operator
value - value to compare column values against

ColumnValueFilter

public ColumnValueFilter(byte[] columnName,
                         ColumnValueFilter.CompareOp compareOp,
                         byte[] value,
                         boolean filterIfColumnMissing)
Constructor.

Parameters:
columnName - name of column
compareOp - operator
value - value to compare column values against
filterIfColumnMissing - if true then we will filter rows that don't have the column.

ColumnValueFilter

public ColumnValueFilter(byte[] columnName,
                         ColumnValueFilter.CompareOp compareOp,
                         WritableByteArrayComparable comparator)
Constructor.

Parameters:
columnName - name of column
compareOp - operator
comparator - Comparator to use.

ColumnValueFilter

public ColumnValueFilter(byte[] columnName,
                         ColumnValueFilter.CompareOp compareOp,
                         WritableByteArrayComparable comparator,
                         boolean filterIfColumnMissing)
Constructor.

Parameters:
columnName - name of column
compareOp - operator
comparator - Comparator to use.
filterIfColumnMissing - if true then we will filter rows that don't have the column.
Method Detail

filterRowKey

public boolean filterRowKey(byte[] rowKey)
Description copied from interface: RowFilterInterface
Filters on just a row key. This is the first chance to stop a row.

Specified by:
filterRowKey in interface RowFilterInterface
Returns:
true if given row key is filtered and row should not be processed.

filterColumn

public boolean filterColumn(byte[] rowKey,
                            byte[] colKey,
                            byte[] data)
Description copied from interface: RowFilterInterface
Filters on row key, column name, and column value. This will take individual columns out of a row, but the rest of the row will still get through.

Specified by:
filterColumn in interface RowFilterInterface
Parameters:
rowKey - row key to filter on.
colKey - column name to filter on
data - column value to filter on
Returns:
true if row filtered and should not be processed.

filterAllRemaining

public boolean filterAllRemaining()
Description copied from interface: RowFilterInterface
Determines if the filter has decided that all remaining results should be filtered (skipped). This is used to prevent the scanner from scanning a the rest of the HRegion when for sure the filter will exclude all remaining rows.

Specified by:
filterAllRemaining in interface RowFilterInterface
Returns:
true if the filter intends to filter all remaining rows.

filterRow

public boolean filterRow(SortedMap<byte[],Cell> columns)
Description copied from interface: RowFilterInterface
Filter on the fully assembled row. This is the last chance to stop a row.

Specified by:
filterRow in interface RowFilterInterface
Returns:
true if row filtered and should not be processed.

processAlways

public boolean processAlways()
Description copied from interface: RowFilterInterface
Returns whether or not the filter should always be processed in any filtering call. This precaution is necessary for filters that maintain state and need to be updated according to their response to filtering calls (see WhileMatchRowFilter for an example). At times, filters nested in RowFilterSets may or may not be called because the RowFilterSet determines a result as fast as possible. Returning true for processAlways() ensures that the filter will always be called.

Specified by:
processAlways in interface RowFilterInterface
Returns:
whether or not to always process the filter

reset

public void reset()
Description copied from interface: RowFilterInterface
Resets the state of the filter. Used prior to the start of a Region scan.

Specified by:
reset in interface RowFilterInterface

rowProcessed

public void rowProcessed(boolean filtered,
                         byte[] key)
Description copied from interface: RowFilterInterface
Called to let filter know the final decision (to pass or filter) on a given row. With out HScanner calling this, the filter does not know if a row passed filtering even if it passed the row itself because other filters may have failed the row. E.g. when this filter is a member of a RowFilterSet with an OR operator.

Specified by:
rowProcessed in interface RowFilterInterface
See Also:
RowFilterSet

validate

public void validate(byte[][] columns)
Description copied from interface: RowFilterInterface
Validates that this filter applies only to a subset of the given columns. This check is done prior to opening of scanner due to the limitation that filtering of columns is dependent on the retrieval of those columns within the HRegion. Criteria on columns that are not part of a scanner's column list will be ignored. In the case of null value filters, all rows will pass the filter. This behavior should be 'undefined' for the user and therefore not permitted.

Specified by:
validate in interface RowFilterInterface

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 © 2008 The Apache Software Foundation