org.apache.hadoop.hbase.filter
Class RegexStringComparator

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

public class RegexStringComparator
extends WritableByteArrayComparable

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]+)?"));
 


Constructor Summary
RegexStringComparator()
          Nullary constructor for Writable, do not use
RegexStringComparator(String expr)
          Constructor
 
Method Summary
 int compareTo(byte[] value)
           
 void readFields(DataInput in)
           
 void setCharset(Charset charset)
          Specifies the Charset to use to convert the row key to a String.
 void write(DataOutput out)
           
 
Methods inherited from class org.apache.hadoop.hbase.filter.WritableByteArrayComparable
getValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegexStringComparator

public RegexStringComparator()
Nullary constructor for Writable, do not use


RegexStringComparator

public RegexStringComparator(String expr)
Constructor

Parameters:
expr - a valid regular expression
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)
Specified by:
compareTo in interface Comparable<byte[]>
Overrides:
compareTo in class WritableByteArrayComparable

readFields

public void readFields(DataInput in)
                throws IOException
Specified by:
readFields in interface org.apache.hadoop.io.Writable
Overrides:
readFields in class WritableByteArrayComparable
Throws:
IOException

write

public void write(DataOutput out)
           throws IOException
Specified by:
write in interface org.apache.hadoop.io.Writable
Overrides:
write in class WritableByteArrayComparable
Throws:
IOException


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