@InterfaceAudience.Public public class RegexStringComparator extends ByteArrayComparable
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));
Pattern
Modifier and Type | Class and Description |
---|---|
(package private) static interface |
RegexStringComparator.Engine
This is an internal interface for abstracting access to different regular
expression matching engines.
|
static class |
RegexStringComparator.EngineType
Engine implementation type (default=JAVA)
|
(package private) static class |
RegexStringComparator.JavaRegexEngine
Implementation of the Engine interface using Java's Pattern.
|
(package private) static class |
RegexStringComparator.JoniRegexEngine
Implementation of the Engine interface using Jruby's joni regex engine.
|
Modifier and Type | Field and Description |
---|---|
private RegexStringComparator.Engine |
engine |
private static org.slf4j.Logger |
LOG |
value
Constructor and Description |
---|
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
|
Modifier and Type | Method and Description |
---|---|
(package private) boolean |
areSerializedFieldsEqual(ByteArrayComparable other) |
int |
compareTo(byte[] value,
int offset,
int length)
Special compareTo method for subclasses, to avoid
copying byte[] unnecessarily.
|
(package private) RegexStringComparator.Engine |
getEngine() |
static RegexStringComparator |
parseFrom(byte[] pbBytes) |
void |
setCharset(Charset charset)
Specifies the
Charset to use to convert the row key to a String. |
byte[] |
toByteArray() |
compareTo, compareTo, getValue
private static final org.slf4j.Logger LOG
private RegexStringComparator.Engine engine
public RegexStringComparator(String expr)
expr
- a valid regular expressionpublic RegexStringComparator(String expr, RegexStringComparator.EngineType engine)
expr
- a valid regular expressionengine
- engine implementation typepublic RegexStringComparator(String expr, int flags)
expr
- a valid regular expressionflags
- java.util.regex.Pattern flagspublic RegexStringComparator(String expr, int flags, RegexStringComparator.EngineType engine)
expr
- a valid regular expressionflags
- java.util.regex.Pattern flagsengine
- engine implementation typepublic void setCharset(Charset charset)
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.
charset
- The charset to use.public int compareTo(byte[] value, int offset, int length)
ByteArrayComparable
compareTo
in class ByteArrayComparable
value
- byte[] to compareoffset
- offset into valuelength
- number of bytes to comparepublic byte[] toByteArray()
toByteArray
in class ByteArrayComparable
public static RegexStringComparator parseFrom(byte[] pbBytes) throws DeserializationException
pbBytes
- A pb serialized RegexStringComparator
instanceRegexStringComparator
made from bytes
DeserializationException
toByteArray()
boolean areSerializedFieldsEqual(ByteArrayComparable other)
areSerializedFieldsEqual
in class ByteArrayComparable
other
- RegexStringComparator.Engine getEngine()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.