org.apache.hadoop.hbase.filter
Class SingleColumnValueFilter

java.lang.Object
  extended by org.apache.hadoop.hbase.filter.Filter
      extended by org.apache.hadoop.hbase.filter.FilterBase
          extended by org.apache.hadoop.hbase.filter.SingleColumnValueFilter
Direct Known Subclasses:
SingleColumnValueExcludeFilter

@InterfaceAudience.Public
@InterfaceStability.Stable
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 ByteArrayComparable.

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 class org.apache.hadoop.hbase.filter.Filter
Filter.ReturnCode
 
Field Summary
protected  byte[] columnFamily
           
protected  byte[] columnQualifier
           
protected  ByteArrayComparable comparator
           
protected  CompareFilter.CompareOp compareOp
           
protected  boolean filterIfMissing
           
protected  boolean foundColumn
           
protected  boolean latestVersionOnly
           
protected  boolean matchedColumn
           
 
Fields inherited from class org.apache.hadoop.hbase.filter.Filter
reversed
 
Constructor Summary
  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, ByteArrayComparable comparator)
          Constructor for binary compare of the value of a single column.
protected SingleColumnValueFilter(byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, ByteArrayComparable comparator, boolean filterIfMissing, boolean latestVersionOnly)
          Constructor for protobuf deserialization only.
 
Method Summary
static Filter createFilterFromArguments(ArrayList<byte[]> filterArguments)
           
 Filter.ReturnCode filterKeyValue(Cell c)
          Filters that dont filter by key value can inherit this implementation that includes all Cells.
 boolean filterRow()
          Filters that never filter by rows based on previously gathered state from FilterBase.filterKeyValue(Cell) can inherit this implementation that never filters a row.
 ByteArrayComparable 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()
           
 boolean hasFilterRow()
          Fitlers that never filter by modifying the returned List of Cells can inherit this implementation that does nothing.
 boolean isFamilyEssential(byte[] name)
          The only CF this filter needs is given column family.
static SingleColumnValueFilter parseFrom(byte[] pbBytes)
           
 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.
 byte[] toByteArray()
          Return length 0 byte array for Filters that don't require special serialization
 String toString()
          Return filter's info for debugging and logging purpose.
 
Methods inherited from class org.apache.hadoop.hbase.filter.FilterBase
filterAllRemaining, filterRow, filterRowCells, filterRowKey, getNextCellHint, getNextKeyHint, transform, transformCell
 
Methods inherited from class org.apache.hadoop.hbase.filter.Filter
isReversed, setReversed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

columnFamily

protected byte[] columnFamily

columnQualifier

protected byte[] columnQualifier

compareOp

protected CompareFilter.CompareOp compareOp

comparator

protected ByteArrayComparable comparator

foundColumn

protected boolean foundColumn

matchedColumn

protected boolean matchedColumn

filterIfMissing

protected boolean filterIfMissing

latestVersionOnly

protected boolean latestVersionOnly
Constructor Detail

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 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
value - value to compare column values against

SingleColumnValueFilter

public SingleColumnValueFilter(byte[] family,
                               byte[] qualifier,
                               CompareFilter.CompareOp compareOp,
                               ByteArrayComparable 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.

SingleColumnValueFilter

protected SingleColumnValueFilter(byte[] family,
                                  byte[] qualifier,
                                  CompareFilter.CompareOp compareOp,
                                  ByteArrayComparable comparator,
                                  boolean filterIfMissing,
                                  boolean latestVersionOnly)
Constructor for protobuf deserialization only.

Parameters:
family -
qualifier -
compareOp -
comparator -
filterIfMissing -
latestVersionOnly -
Method Detail

getOperator

public CompareFilter.CompareOp getOperator()
Returns:
operator

getComparator

public ByteArrayComparable getComparator()
Returns:
the comparator

getFamily

public byte[] getFamily()
Returns:
the family

getQualifier

public byte[] getQualifier()
Returns:
the qualifier

filterKeyValue

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

Overrides:
filterKeyValue in class FilterBase
Parameters:
c - the Cell 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(Cell) can inherit this implementation that never filters a row.

Overrides:
filterRow in class FilterBase
Returns:
true to exclude row, false to include row.

hasFilterRow

public boolean hasFilterRow()
Description copied from class: FilterBase
Fitlers that never filter by modifying the returned List of Cells can inherit this implementation that does nothing.

Overrides:
hasFilterRow in class FilterBase
Returns:
True if this filter actively uses filterRow(List) or filterRow().

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.

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

createFilterFromArguments

public static Filter createFilterFromArguments(ArrayList<byte[]> filterArguments)

toByteArray

public byte[] toByteArray()
Description copied from class: FilterBase
Return length 0 byte array for Filters that don't require special serialization

Overrides:
toByteArray in class FilterBase
Returns:
The filter serialized using pb

parseFrom

public static SingleColumnValueFilter parseFrom(byte[] pbBytes)
                                         throws DeserializationException
Parameters:
pbBytes - A pb serialized SingleColumnValueFilter instance
Returns:
An instance of SingleColumnValueFilter made from bytes
Throws:
DeserializationException
See Also:
toByteArray()

isFamilyEssential

public boolean isFamilyEssential(byte[] name)
The only CF this filter needs is given column family. So, it's the only essential column in whole scan. If filterIfMissing == false, all families are essential, because of possibility of skipping the rows without any data in filtered CF.

Overrides:
isFamilyEssential in class FilterBase

toString

public String toString()
Description copied from class: FilterBase
Return filter's info for debugging and logging purpose.

Overrides:
toString in class FilterBase


Copyright © 2007–2016 The Apache Software Foundation. All rights reserved.