org.apache.hadoop.hbase.filter
Class RegexStringComparator

java.lang.Object
  extended by org.apache.hadoop.hbase.filter.ByteArrayComparable
      extended by org.apache.hadoop.hbase.filter.RegexStringComparator
All Implemented Interfaces:
Comparable<byte[]>

@InterfaceAudience.Public
@InterfaceStability.Stable
public class RegexStringComparator
extends ByteArrayComparable

This comparator is for use with CompareFilter implementations, such as RowFilter, QualifierFilter, and ValueFilter, for filtering based on the value of a given column. Use it to test if a given regular expression matches a cell value in the column.

Only EQUAL or NOT_EQUAL comparisons are valid with this comparator.

For example:

 ValueFilter vf = new ValueFilter(CompareOp.EQUAL,
     new RegexStringComparator(
       // v4 IP address
       "(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3,3}" +
         "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(\\/[0-9]+)?" +
         "|" +
       // v6 IP address
       "((([\\dA-Fa-f]{1,4}:){7}[\\dA-Fa-f]{1,4})(:([\\d]{1,3}.)" +
         "{3}[\\d]{1,3})?)(\\/[0-9]+)?"));
 

Supports Pattern flags as well:

 ValueFilter vf = new ValueFilter(CompareOp.EQUAL,
     new RegexStringComparator("regex", Pattern.CASE_INSENSITIVE | Pattern.DOTALL));
 

See Also:
Pattern

Nested Class Summary
static class RegexStringComparator.EngineType
          Engine implementation type (default=JAVA)
 
Constructor Summary
RegexStringComparator(String expr)
          Constructor Adds Pattern.DOTALL to the underlying Pattern
RegexStringComparator(String expr, int flags)
          Constructor
RegexStringComparator(String expr, int flags, RegexStringComparator.EngineType engine)
          Constructor
RegexStringComparator(String expr, RegexStringComparator.EngineType engine)
          Constructor Adds Pattern.DOTALL to the underlying Pattern
 
Method Summary
 int compareTo(byte[] value, int offset, int length)
          Special compareTo method for subclasses, to avoid copying byte[] unnecessarily.
static RegexStringComparator parseFrom(byte[] pbBytes)
           
 void setCharset(Charset charset)
          Specifies the Charset to use to convert the row key to a String.
 byte[] toByteArray()
           
 
Methods inherited from class org.apache.hadoop.hbase.filter.ByteArrayComparable
compareTo, getValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegexStringComparator

public RegexStringComparator(String expr)
Constructor Adds Pattern.DOTALL to the underlying Pattern

Parameters:
expr - a valid regular expression

RegexStringComparator

public RegexStringComparator(String expr,
                             RegexStringComparator.EngineType engine)
Constructor Adds Pattern.DOTALL to the underlying Pattern

Parameters:
expr - a valid regular expression
engine - engine implementation type

RegexStringComparator

public RegexStringComparator(String expr,
                             int flags)
Constructor

Parameters:
expr - a valid regular expression
flags - java.util.regex.Pattern flags

RegexStringComparator

public RegexStringComparator(String expr,
                             int flags,
                             RegexStringComparator.EngineType engine)
Constructor

Parameters:
expr - a valid regular expression
flags - java.util.regex.Pattern flags
engine - engine implementation type
Method Detail

setCharset

public void setCharset(Charset charset)
Specifies the Charset to use to convert the row key to a String.

The row key needs to be converted to a String in order to be matched against the regular expression. This method controls which charset is used to do this conversion.

If the row key is made of arbitrary bytes, the charset ISO-8859-1 is recommended.

Parameters:
charset - The charset to use.

compareTo

public int compareTo(byte[] value,
                     int offset,
                     int length)
Description copied from class: ByteArrayComparable
Special compareTo method for subclasses, to avoid copying byte[] unnecessarily.

Specified by:
compareTo in class ByteArrayComparable
Parameters:
value - byte[] to compare
offset - offset into value
length - number of bytes to compare
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

toByteArray

public byte[] toByteArray()
Specified by:
toByteArray in class ByteArrayComparable
Returns:
The comparator serialized using pb

parseFrom

public static RegexStringComparator parseFrom(byte[] pbBytes)
                                       throws org.apache.hadoop.hbase.exceptions.DeserializationException
Parameters:
pbBytes - A pb serialized RegexStringComparator instance
Returns:
An instance of RegexStringComparator made from bytes
Throws:
org.apache.hadoop.hbase.exceptions.DeserializationException
See Also:
toByteArray()


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