org.apache.hadoop.hbase.filter
Class SingleColumnValueFilter

java.lang.Object
  extended by org.apache.hadoop.hbase.filter.FilterBase
      extended by org.apache.hadoop.hbase.filter.SingleColumnValueFilter
All Implemented Interfaces:
Filter, org.apache.hadoop.io.Writable
Direct Known Subclasses:
SingleColumnValueExcludeFilter

public class SingleColumnValueFilter
extends FilterBase

This filter is used to filter cells based on value. It takes a CompareFilter.CompareOp operator (equal, greater, not equal, etc), and either a byte [] value or a WritableByteArrayComparable.

If we have a byte [] value then we just do a lexicographic compare. For example, if passed value is 'b' and cell has 'a' and the compare operator is LESS, then we will filter out this cell (return true). 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.

You must also specify a family and qualifier. Only the value of this column will be tested. When using this filter on a Scan with specified inputs, the column to be tested should also be added as input (otherwise the filter will regard the column as missing).

To prevent the entire row from being emitted if the column is not found on a row, use setFilterIfMissing(boolean). Otherwise, if the column is found, the entire row will be emitted only if the value passes. If the value fails, the row will be filtered out.

In order to test values of previous versions (timestamps), set setLatestVersionOnly(boolean) to false. The default is true, meaning that only the latest version's value is tested and all previous versions are ignored.

To filter based on the value of all scanned columns, use ValueFilter.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.hadoop.hbase.filter.Filter
Filter.ReturnCode
 
Field Summary
protected  byte[] columnFamily
           
protected  byte[] columnQualifier
           
 
Constructor Summary
SingleColumnValueFilter()
          Writable constructor, do not use.
SingleColumnValueFilter(byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, byte[] value)
          Constructor for binary compare of the value of a single column.
SingleColumnValueFilter(byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, WritableByteArrayComparable comparator)
          Constructor for binary compare of the value of a single column.
 
Method Summary
 Filter.ReturnCode filterKeyValue(KeyValue keyValue)
          Filters that dont filter by key value can inherit this implementation that includes all KeyValues.
 boolean filterRow()
          Filters that never filter by rows based on previously gathered state from FilterBase.filterKeyValue(KeyValue) can inherit this implementation that never filters a row.
 WritableByteArrayComparable getComparator()
           
 byte[] getFamily()
           
 boolean getFilterIfMissing()
          Get whether entire row should be filtered if column is not found.
 boolean getLatestVersionOnly()
          Get whether only the latest version of the column value should be compared.
 CompareFilter.CompareOp getOperator()
           
 byte[] getQualifier()
           
 void readFields(DataInput in)
           
 void reset()
          Filters that are purely stateless and do nothing in their reset() methods can inherit this null/empty implementation.
 void setFilterIfMissing(boolean filterIfMissing)
          Set whether entire row should be filtered if column is not found.
 void setLatestVersionOnly(boolean latestVersionOnly)
          Set whether only the latest version of the column value should be compared.
 void write(DataOutput out)
           
 
Methods inherited from class org.apache.hadoop.hbase.filter.FilterBase
filterAllRemaining, filterRow, filterRowKey, getNextKeyHint, hasFilterRow
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

columnFamily

protected byte[] columnFamily

columnQualifier

protected byte[] columnQualifier
Constructor Detail

SingleColumnValueFilter

public SingleColumnValueFilter()
Writable constructor, do not use.


SingleColumnValueFilter

public SingleColumnValueFilter(byte[] family,
                               byte[] qualifier,
                               CompareFilter.CompareOp compareOp,
                               byte[] value)
Constructor for binary compare of the value of a single column. If the column is found and the condition passes, all columns of the row will be emitted. If the column is not found or the condition fails, the row will not be emitted.

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

SingleColumnValueFilter

public SingleColumnValueFilter(byte[] family,
                               byte[] qualifier,
                               CompareFilter.CompareOp compareOp,
                               WritableByteArrayComparable comparator)
Constructor for binary compare of the value of a single column. If the column is found and the condition passes, all columns of the row will be emitted. If the condition fails, the row will not be emitted.

Use the filterIfColumnMissing flag to set whether the rest of the columns in a row will be emitted if the specified column to check is not found in the row.

Parameters:
family - name of column family
qualifier - name of column qualifier
compareOp - operator
comparator - Comparator to use.
Method Detail

getOperator

public CompareFilter.CompareOp getOperator()
Returns:
operator

getComparator

public WritableByteArrayComparable getComparator()
Returns:
the comparator

getFamily

public byte[] getFamily()
Returns:
the family

getQualifier

public byte[] getQualifier()
Returns:
the qualifier

filterKeyValue

public Filter.ReturnCode filterKeyValue(KeyValue keyValue)
Description copied from class: FilterBase
Filters that dont filter by key value can inherit this implementation that includes all KeyValues.

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

filterRow

public boolean filterRow()
Description copied from class: FilterBase
Filters that never filter by rows based on previously gathered state from FilterBase.filterKeyValue(KeyValue) can inherit this implementation that never filters a row.

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

reset

public void reset()
Description copied from class: FilterBase
Filters that are purely stateless and do nothing in their reset() methods can inherit this null/empty implementation.

Specified by:
reset in interface Filter
Overrides:
reset in class FilterBase

getFilterIfMissing

public boolean getFilterIfMissing()
Get whether entire row should be filtered if column is not found.

Returns:
true if row should be skipped if column not found, false if row should be let through anyways

setFilterIfMissing

public void setFilterIfMissing(boolean filterIfMissing)
Set whether entire row should be filtered if column is not found.

If true, the entire row will be skipped if the column is not found.

If false, the row will pass if the column is not found. This is default.

Parameters:
filterIfMissing - flag

getLatestVersionOnly

public boolean getLatestVersionOnly()
Get whether only the latest version of the column value should be compared. If true, the row will be returned if only the latest version of the column value matches. If false, the row will be returned if any version of the column value matches. The default is true.

Returns:
return value

setLatestVersionOnly

public void setLatestVersionOnly(boolean latestVersionOnly)
Set whether only the latest version of the column value should be compared. If true, the row will be returned if only the latest version of the column value matches. If false, the row will be returned if any version of the column value matches. The default is true.

Parameters:
latestVersionOnly - flag

readFields

public void readFields(DataInput in)
                throws IOException
Throws:
IOException

write

public void write(DataOutput out)
           throws IOException
Throws:
IOException


Copyright © 2011 The Apache Software Foundation. All Rights Reserved.