Class SingleColumnValueFilter

Direct Known Subclasses:
SingleColumnValueExcludeFilter

@Public public class SingleColumnValueFilter extends FilterBase
This filter is used to filter cells based on value. It takes a CompareOperator 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 CellScanner 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.

  • Field Details

  • Constructor Details

    • SingleColumnValueFilter

      public SingleColumnValueFilter(byte[] family, byte[] qualifier, CompareOperator op, 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
      op - operator
      value - value to compare column values against
    • SingleColumnValueFilter

      public SingleColumnValueFilter(byte[] family, byte[] qualifier, CompareOperator op, 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
      op - operator
      comparator - Comparator to use.
    • SingleColumnValueFilter

      protected SingleColumnValueFilter(byte[] family, byte[] qualifier, CompareOperator op, ByteArrayComparable comparator, boolean filterIfMissing, boolean latestVersionOnly)
      Constructor for protobuf deserialization only.
  • Method Details

    • getCompareOperator

    • getComparator

      Returns the comparator
    • getFamily

      public byte[] getFamily()
      Returns the family
    • getQualifier

      public byte[] getQualifier()
      Returns the qualifier
    • filterRowKey

      public boolean filterRowKey(Cell cell) throws IOException
      Description copied from class: 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.filterCell(Cell) below. If Filter.filterAllRemaining() returns true, then Filter.filterRowKey(Cell) should also return true. Concrete implementers can signal a failure condition in their code by throwing an IOException.
      Overrides:
      filterRowKey in class FilterBase
      Parameters:
      cell - The first cell coming in the new row
      Returns:
      true, remove entire row, false, include the row (maybe).
      Throws:
      IOException - in case an I/O or an filter specific failure needs to be signaled.
    • filterCell

      Description copied from class: 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 filterRowKey returns true, filterCell needs to be consistent with it. filterCell can assume that filterRowKey has already been called for the row. 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. Concrete implementers can signal a failure condition in their code by throwing an IOException.
      Overrides:
      filterCell in class Filter
      Parameters:
      c - the Cell in question
      Returns:
      code as described below
      See Also:
    • filterColumnValue

      private boolean filterColumnValue(Cell cell)
    • filterRow

      public boolean filterRow()
      Description copied from class: FilterBase
      Filters that never filter by rows based on previously gathered state from Filter.filterCell(Cell) can inherit this implementation that never filters a row. Last chance to veto row based on previous Filter.filterCell(Cell) 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). Concrete implementers can signal a failure condition in their code by throwing an IOException.
      Overrides:
      filterRow in class FilterBase
      Returns:
      true to exclude row, false to include row.
    • hasFilterRow

      public boolean hasFilterRow()
      Description copied from class: FilterBase
      Filters that never filter by modifying the returned List of Cells can inherit this implementation that does nothing. Primarily used to check for conflicts with scans(such as scans that do not read a full row at a time).
      Overrides:
      hasFilterRow in class FilterBase
      Returns:
      True if this filter actively uses filterRowCells(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. Reset the state of the filter between rows. Concrete implementers can signal a failure condition in their code by throwing an IOException.
      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)
    • convert

      org.apache.hadoop.hbase.shaded.protobuf.generated.FilterProtos.SingleColumnValueFilter convert()
    • toByteArray

      public byte[] toByteArray()
      Returns The filter serialized using pb
      Overrides:
      toByteArray in class FilterBase
      Returns:
      The filter serialized using pb
    • parseFrom

      public static SingleColumnValueFilter parseFrom(byte[] pbBytes) throws DeserializationException
      Parse a serialized representation of SingleColumnValueFilter
      Parameters:
      pbBytes - A pb serialized SingleColumnValueFilter instance
      Returns:
      An instance of SingleColumnValueFilter made from bytes
      Throws:
      DeserializationException - if an error occurred
      See Also:
    • areSerializedFieldsEqual

      Returns true if and only if the fields of the filter that are serialized are equal to the corresponding fields in other. Used for testing.
      Overrides:
      areSerializedFieldsEqual in class FilterBase
      Returns:
      true if and only if the fields of the filter that are serialized are equal to the corresponding fields in other. Used for testing.
    • 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
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object