@InterfaceAudience.Public public class ParseFilter extends Object
This class addresses the HBASE-4168 JIRA. More documentation on this Filter Language can be found at: https://issues.apache.org/jira/browse/HBASE-4176
Modifier and Type | Field and Description |
---|---|
private static HashMap<String,String> |
filterHashMap |
private static org.slf4j.Logger |
LOG |
private static HashMap<ByteBuffer,Integer> |
operatorPrecedenceHashMap |
Constructor and Description |
---|
ParseFilter() |
Modifier and Type | Method and Description |
---|---|
static boolean |
checkForAnd(byte[] filterStringAsByteArray,
int indexOfAnd)
Checks if the current index of filter string we are on is the beginning of the keyword 'AND'
|
static boolean |
checkForOr(byte[] filterStringAsByteArray,
int indexOfOr)
Checks if the current index of filter string we are on is the beginning of the keyword 'OR'
|
static boolean |
checkForSkip(byte[] filterStringAsByteArray,
int indexOfSkip)
Checks if the current index of filter string we are on is the beginning of the keyword 'SKIP'
|
static boolean |
checkForWhile(byte[] filterStringAsByteArray,
int indexOfWhile)
Checks if the current index of filter string we are on is the beginning of the keyword 'WHILE'
|
static boolean |
convertByteArrayToBoolean(byte[] booleanAsByteArray)
Converts a boolean expressed in a byte array to an actual boolean
|
static int |
convertByteArrayToInt(byte[] numberAsByteArray)
Converts an int expressed in a byte array to an actual int
|
static long |
convertByteArrayToLong(byte[] numberAsByteArray)
Converts a long expressed in a byte array to an actual long
|
static ByteArrayComparable |
createComparator(byte[] comparator)
Parses a comparator of the form comparatorType:comparatorValue form and returns a comparator
|
static CompareFilter.CompareOp |
createCompareOp(byte[] compareOpAsByteArray)
Deprecated.
Since 2.0
|
static CompareOperator |
createCompareOperator(byte[] compareOpAsByteArray)
Takes a compareOperator symbol as a byte array and returns the corresponding CompareOperator
|
static byte[] |
createUnescapdArgument(byte[] filterStringAsByteArray,
int argumentStartIndex,
int argumentEndIndex)
Removes the single quote escaping a single quote - thus it returns an unescaped argument
|
byte[] |
extractFilterSimpleExpression(byte[] filterStringAsByteArray,
int filterExpressionStartOffset)
Extracts a simple filter expression from the filter string given by the user
|
static Map<String,String> |
getAllFilters()
Returns all known filters
|
static ArrayList<byte[]> |
getFilterArguments(byte[] filterStringAsByteArray)
Returns the arguments of the filter from the filter string
|
static byte[] |
getFilterName(byte[] filterStringAsByteArray)
Returns the filter name given a simple filter expression
|
Set<String> |
getSupportedFilters()
Return a Set of filters supported by the Filter Language
|
boolean |
hasHigherPriority(ByteBuffer a,
ByteBuffer b)
Returns which operator has higher precedence
|
static boolean |
isQuoteUnescaped(byte[] array,
int quoteIndex)
Returns a boolean indicating whether the quote was escaped or not
|
static byte[][] |
parseComparator(byte[] comparator)
Splits a column in comparatorType:comparatorValue form into separate byte arrays
|
Filter |
parseFilterString(byte[] filterStringAsByteArray)
Parses the filterString and constructs a filter using it
|
Filter |
parseFilterString(String filterString)
Parses the filterString and constructs a filter using it
|
Filter |
parseSimpleFilterExpression(byte[] filterStringAsByteArray)
Constructs a filter object given a simple filter expression
|
static Filter |
popArguments(Stack<ByteBuffer> operatorStack,
Stack<Filter> filterStack)
Pops an argument from the operator stack and the number of arguments required by the operator
from the filterStack and evaluates them
|
void |
reduce(Stack<ByteBuffer> operatorStack,
Stack<Filter> filterStack,
ByteBuffer operator)
This function is called while parsing the filterString and an operator is parsed
|
static void |
registerFilter(String name,
String filterClass)
Register a new filter with the parser.
|
static byte[] |
removeQuotesFromByteArray(byte[] quotedByteArray)
Takes a quoted byte array and converts it into an unquoted byte array
For example: given a byte array representing 'abc', it returns a
byte array representing abc
|
private static final org.slf4j.Logger LOG
private static HashMap<ByteBuffer,Integer> operatorPrecedenceHashMap
private static HashMap<String,String> filterHashMap
public ParseFilter()
public Filter parseFilterString(String filterString) throws CharacterCodingException
filterString
- filter string given by the userCharacterCodingException
public Filter parseFilterString(byte[] filterStringAsByteArray) throws CharacterCodingException
filterStringAsByteArray
- filter string given by the userCharacterCodingException
public byte[] extractFilterSimpleExpression(byte[] filterStringAsByteArray, int filterExpressionStartOffset) throws CharacterCodingException
A simpleFilterExpression is of the form: FilterName('arg', 'arg', 'arg') The user given filter string can have many simpleFilterExpressions combined using operators.
This function extracts a simpleFilterExpression from the larger filterString given the start offset of the simpler expression
filterStringAsByteArray
- filter string given by the userfilterExpressionStartOffset
- start index of the simple filter expressionCharacterCodingException
public Filter parseSimpleFilterExpression(byte[] filterStringAsByteArray) throws CharacterCodingException
filterStringAsByteArray
- filter string given by the userCharacterCodingException
public static byte[] getFilterName(byte[] filterStringAsByteArray)
filterStringAsByteArray
- a simple filter expressionpublic static ArrayList<byte[]> getFilterArguments(byte[] filterStringAsByteArray)
filterStringAsByteArray
- filter string given by the userpublic void reduce(Stack<ByteBuffer> operatorStack, Stack<Filter> filterStack, ByteBuffer operator)
operatorStack
- the stack containing the operators and parenthesisfilterStack
- the stack containing the filtersoperator
- the operator found while parsing the filterStringpublic static Filter popArguments(Stack<ByteBuffer> operatorStack, Stack<Filter> filterStack)
operatorStack
- the stack containing the operatorsfilterStack
- the stack containing the filterspublic boolean hasHigherPriority(ByteBuffer a, ByteBuffer b)
If a has higher precedence than b, it returns true If they have the same precedence, it returns false
public static byte[] createUnescapdArgument(byte[] filterStringAsByteArray, int argumentStartIndex, int argumentEndIndex)
filterStringAsByteArray
- filter string given by userargumentStartIndex
- start index of the argumentargumentEndIndex
- end index of the argumentpublic static boolean checkForOr(byte[] filterStringAsByteArray, int indexOfOr) throws CharacterCodingException, ArrayIndexOutOfBoundsException
filterStringAsByteArray
- filter string given by the userindexOfOr
- index at which an 'O' was readCharacterCodingException
ArrayIndexOutOfBoundsException
public static boolean checkForAnd(byte[] filterStringAsByteArray, int indexOfAnd) throws CharacterCodingException
filterStringAsByteArray
- filter string given by the userindexOfAnd
- index at which an 'A' was readCharacterCodingException
public static boolean checkForSkip(byte[] filterStringAsByteArray, int indexOfSkip) throws CharacterCodingException
filterStringAsByteArray
- filter string given by the userindexOfSkip
- index at which an 'S' was readCharacterCodingException
public static boolean checkForWhile(byte[] filterStringAsByteArray, int indexOfWhile) throws CharacterCodingException
filterStringAsByteArray
- filter string given by the userindexOfWhile
- index at which an 'W' was readCharacterCodingException
public static boolean isQuoteUnescaped(byte[] array, int quoteIndex)
array
- byte array in which the quote was foundquoteIndex
- index of the single quotepublic static byte[] removeQuotesFromByteArray(byte[] quotedByteArray)
quotedByteArray
- the quoted byte arraypublic static int convertByteArrayToInt(byte[] numberAsByteArray)
This doesn't use Bytes.toInt because that assumes
that there will be Bytes.SIZEOF_INT
bytes available.
numberAsByteArray
- the int value expressed as a byte arraypublic static long convertByteArrayToLong(byte[] numberAsByteArray)
This doesn't use Bytes.toLong because that assumes
that there will be Bytes.SIZEOF_INT
bytes available.
numberAsByteArray
- the long value expressed as a byte arraypublic static boolean convertByteArrayToBoolean(byte[] booleanAsByteArray)
This doesn't used Bytes.toBoolean because Bytes.toBoolean(byte []) assumes that 1 stands for true and 0 for false. Here, the byte array representing "true" and "false" is parsed
booleanAsByteArray
- the boolean value expressed as a byte arraypublic static CompareOperator createCompareOperator(byte[] compareOpAsByteArray)
compareOpAsByteArray
- the comparatorOperator symbol as a byte array@Deprecated public static CompareFilter.CompareOp createCompareOp(byte[] compareOpAsByteArray)
compareOpAsByteArray
- the comparatorOperator symbol as a byte arraypublic static ByteArrayComparable createComparator(byte[] comparator)
comparator
- the comparator in the form comparatorType:comparatorValuepublic static byte[][] parseComparator(byte[] comparator)
comparator
- the comparatorpublic Set<String> getSupportedFilters()
public static Map<String,String> getAllFilters()
public static void registerFilter(String name, String filterClass)
name
- a name for the filterfilterClass
- fully qualified class nameCopyright © 2007–2020 The Apache Software Foundation. All rights reserved.