Package org.apache.hadoop.hbase.filter
Class RegexStringComparator
java.lang.Object
org.apache.hadoop.hbase.filter.ByteArrayComparable
org.apache.hadoop.hbase.filter.RegexStringComparator
- All Implemented Interfaces:
Comparable<byte[]>
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static interfaceThis is an internal interface for abstracting access to different regular expression matching engines.static enumEngine implementation type (default=JAVA)(package private) static classImplementation of the Engine interface using Java's Pattern.(package private) static classImplementation of the Engine interface using Jruby's joni regex engine. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate RegexStringComparator.Engineprivate static final org.slf4j.LoggerFields inherited from class org.apache.hadoop.hbase.filter.ByteArrayComparable
value -
Constructor Summary
ConstructorsConstructorDescriptionRegexStringComparator(String expr) Constructor Adds Pattern.DOTALL to the underlying PatternRegexStringComparator(String expr, int flags) ConstructorRegexStringComparator(String expr, int flags, RegexStringComparator.EngineType engine) ConstructorRegexStringComparator(String expr, RegexStringComparator.EngineType engine) Constructor Adds Pattern.DOTALL to the underlying Pattern -
Method Summary
Modifier and TypeMethodDescription(package private) booleanReturns true if and only if the fields of the comparator that are serialized are equal to the corresponding fields in other.intcompareTo(byte[] value, int offset, int length) Special compareTo method for subclasses, to avoid copying byte[] unnecessarily.(package private) RegexStringComparator.Enginestatic RegexStringComparatorparseFrom(byte[] pbBytes) Parse a serialized representation ofRegexStringComparatorvoidsetCharset(Charset charset) Specifies theCharsetto use to convert the row key to a String.byte[]Returns The comparator serialized using pbMethods inherited from class org.apache.hadoop.hbase.filter.ByteArrayComparable
compareTo, compareTo, getValue
-
Field Details
-
LOG
-
engine
-
-
Constructor Details
-
RegexStringComparator
Constructor Adds Pattern.DOTALL to the underlying Pattern- Parameters:
expr- a valid regular expression
-
RegexStringComparator
Constructor Adds Pattern.DOTALL to the underlying Pattern- Parameters:
expr- a valid regular expressionengine- engine implementation type
-
RegexStringComparator
Constructor- Parameters:
expr- a valid regular expressionflags- java.util.regex.Pattern flags
-
RegexStringComparator
Constructor- Parameters:
expr- a valid regular expressionflags- java.util.regex.Pattern flagsengine- engine implementation type
-
-
Method Details
-
setCharset
Specifies theCharsetto 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-1is recommended.- Parameters:
charset- The charset to use.
-
compareTo
Description copied from class:ByteArrayComparableSpecial compareTo method for subclasses, to avoid copying byte[] unnecessarily.- Specified by:
compareToin classByteArrayComparable- Parameters:
value- byte[] to compareoffset- offset into valuelength- 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
Returns The comparator serialized using pb- Specified by:
toByteArrayin classByteArrayComparable
-
parseFrom
Parse a serialized representation ofRegexStringComparator- Parameters:
pbBytes- A pb serializedRegexStringComparatorinstance- Returns:
- An instance of
RegexStringComparatormade frombytes - Throws:
DeserializationException- if an error occurred- See Also:
-
areSerializedFieldsEqual
Returns true if and only if the fields of the comparator that are serialized are equal to the corresponding fields in other. Used for testing.- Overrides:
areSerializedFieldsEqualin classByteArrayComparable
-
getEngine
-