Class ParseFilter
This class addresses the HBASE-4176 JIRA. More documentation on this Filter Language can be found at: https://issues.apache.org/jira/browse/HBASE-4176
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final org.slf4j.Logger
private static HashMap<ByteBuffer,
Integer> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 booleanstatic int
convertByteArrayToInt
(byte[] numberAsByteArray) Converts an int expressed in a byte array to an actual intstatic long
convertByteArrayToLong
(byte[] numberAsByteArray) Converts a long expressed in a byte array to an actual longstatic ByteArrayComparable
createComparator
(byte[] comparator) Parses a comparator of the form comparatorType:comparatorValue form and returns a comparatorstatic CompareOperator
createCompareOperator
(byte[] compareOpAsByteArray) Takes a compareOperator symbol as a byte array and returns the corresponding CompareOperatorstatic byte[]
createUnescapdArgument
(byte[] filterStringAsByteArray, int argumentStartIndex, int argumentEndIndex) Removes the single quote escaping a single quote - thus it returns an unescaped argumentbyte[]
extractFilterSimpleExpression
(byte[] filterStringAsByteArray, int filterExpressionStartOffset) Extracts a simple filter expression from the filter string given by the userReturns all known filtersstatic ArrayList<byte[]>
getFilterArguments
(byte[] filterStringAsByteArray) Returns the arguments of the filter from the filter stringstatic byte[]
getFilterName
(byte[] filterStringAsByteArray) Returns the filter name given a simple filter expressionReturn a Set of filters supported by the Filter Languageboolean
Returns which operator has higher precedencestatic boolean
isQuoteUnescaped
(byte[] array, int quoteIndex) Returns a boolean indicating whether the quote was escaped or notstatic byte[][]
parseComparator
(byte[] comparator) Splits a column in comparatorType:comparatorValue form into separate byte arraysparseFilterString
(byte[] filterStringAsByteArray) Parses the filterString and constructs a filter using itparseFilterString
(String filterString) Parses the filterString and constructs a filter using itparseSimpleFilterExpression
(byte[] filterStringAsByteArray) Constructs a filter object given a simple filter expressionstatic 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 themvoid
reduce
(Stack<ByteBuffer> operatorStack, Stack<Filter> filterStack, ByteBuffer operator) This function is called while parsing the filterString and an operator is parsedstatic 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
-
Field Details
-
LOG
-
operatorPrecedenceHashMap
-
filterHashMap
-
-
Constructor Details
-
ParseFilter
public ParseFilter()
-
-
Method Details
-
parseFilterString
Parses the filterString and constructs a filter using it- Parameters:
filterString
- filter string given by the user- Returns:
- filter object we constructed
- Throws:
CharacterCodingException
-
parseFilterString
Parses the filterString and constructs a filter using it- Parameters:
filterStringAsByteArray
- filter string given by the user- Returns:
- filter object we constructed
- Throws:
CharacterCodingException
-
extractFilterSimpleExpression
public byte[] extractFilterSimpleExpression(byte[] filterStringAsByteArray, int filterExpressionStartOffset) throws CharacterCodingException Extracts a simple filter expression from the filter string given by the userA 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
- Parameters:
filterStringAsByteArray
- filter string given by the userfilterExpressionStartOffset
- start index of the simple filter expression- Returns:
- byte array containing the simple filter expression
- Throws:
CharacterCodingException
-
parseSimpleFilterExpression
public Filter parseSimpleFilterExpression(byte[] filterStringAsByteArray) throws CharacterCodingException Constructs a filter object given a simple filter expression- Parameters:
filterStringAsByteArray
- filter string given by the user- Returns:
- filter object we constructed
- Throws:
CharacterCodingException
-
getFilterName
Returns the filter name given a simple filter expression- Parameters:
filterStringAsByteArray
- a simple filter expression- Returns:
- name of filter in the simple filter expression
-
getFilterArguments
Returns the arguments of the filter from the filter string- Parameters:
filterStringAsByteArray
- filter string given by the user- Returns:
- an ArrayList containing the arguments of the filter in the filter string
-
reduce
This function is called while parsing the filterString and an operator is parsed- Parameters:
operatorStack
- the stack containing the operators and parenthesisfilterStack
- the stack containing the filtersoperator
- the operator found while parsing the filterString
-
popArguments
Pops an argument from the operator stack and the number of arguments required by the operator from the filterStack and evaluates them- Parameters:
operatorStack
- the stack containing the operatorsfilterStack
- the stack containing the filters- Returns:
- the evaluated filter
-
hasHigherPriority
Returns which operator has higher precedenceIf a has higher precedence than b, it returns true If they have the same precedence, it returns false
-
createUnescapdArgument
public static byte[] createUnescapdArgument(byte[] filterStringAsByteArray, int argumentStartIndex, int argumentEndIndex) Removes the single quote escaping a single quote - thus it returns an unescaped argument- Parameters:
filterStringAsByteArray
- filter string given by userargumentStartIndex
- start index of the argumentargumentEndIndex
- end index of the argument- Returns:
- returns an unescaped argument
-
checkForOr
public static boolean checkForOr(byte[] filterStringAsByteArray, int indexOfOr) throws CharacterCodingException, ArrayIndexOutOfBoundsException Checks if the current index of filter string we are on is the beginning of the keyword 'OR'- Parameters:
filterStringAsByteArray
- filter string given by the userindexOfOr
- index at which an 'O' was read- Returns:
- true if the keyword 'OR' is at the current index
- Throws:
CharacterCodingException
ArrayIndexOutOfBoundsException
-
checkForAnd
public static boolean checkForAnd(byte[] filterStringAsByteArray, int indexOfAnd) throws CharacterCodingException Checks if the current index of filter string we are on is the beginning of the keyword 'AND'- Parameters:
filterStringAsByteArray
- filter string given by the userindexOfAnd
- index at which an 'A' was read- Returns:
- true if the keyword 'AND' is at the current index
- Throws:
CharacterCodingException
-
checkForSkip
public static boolean checkForSkip(byte[] filterStringAsByteArray, int indexOfSkip) throws CharacterCodingException Checks if the current index of filter string we are on is the beginning of the keyword 'SKIP'- Parameters:
filterStringAsByteArray
- filter string given by the userindexOfSkip
- index at which an 'S' was read- Returns:
- true if the keyword 'SKIP' is at the current index
- Throws:
CharacterCodingException
-
checkForWhile
public static boolean checkForWhile(byte[] filterStringAsByteArray, int indexOfWhile) throws CharacterCodingException Checks if the current index of filter string we are on is the beginning of the keyword 'WHILE'- Parameters:
filterStringAsByteArray
- filter string given by the userindexOfWhile
- index at which an 'W' was read- Returns:
- true if the keyword 'WHILE' is at the current index
- Throws:
CharacterCodingException
-
isQuoteUnescaped
Returns a boolean indicating whether the quote was escaped or not- Parameters:
array
- byte array in which the quote was foundquoteIndex
- index of the single quote- Returns:
- returns true if the quote was unescaped
-
removeQuotesFromByteArray
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- Parameters:
quotedByteArray
- the quoted byte array- Returns:
- Unquoted byte array
-
convertByteArrayToInt
Converts an int expressed in a byte array to an actual intThis doesn't use Bytes.toInt because that assumes that there will be
Bytes.SIZEOF_INT
bytes available.- Parameters:
numberAsByteArray
- the int value expressed as a byte array- Returns:
- the int value
-
convertByteArrayToLong
Converts a long expressed in a byte array to an actual longThis doesn't use Bytes.toLong because that assumes that there will be
Bytes.SIZEOF_INT
bytes available.- Parameters:
numberAsByteArray
- the long value expressed as a byte array- Returns:
- the long value
-
convertByteArrayToBoolean
Converts a boolean expressed in a byte array to an actual booleanThis 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
- Parameters:
booleanAsByteArray
- the boolean value expressed as a byte array- Returns:
- the boolean value
-
createCompareOperator
Takes a compareOperator symbol as a byte array and returns the corresponding CompareOperator- Parameters:
compareOpAsByteArray
- the comparatorOperator symbol as a byte array- Returns:
- the Compare Operator
-
createComparator
Parses a comparator of the form comparatorType:comparatorValue form and returns a comparator- Parameters:
comparator
- the comparator in the form comparatorType:comparatorValue- Returns:
- the parsed comparator
-
parseComparator
Splits a column in comparatorType:comparatorValue form into separate byte arrays- Parameters:
comparator
- the comparator- Returns:
- the parsed arguments of the comparator as a 2D byte array
-
getSupportedFilters
Return a Set of filters supported by the Filter Language -
getAllFilters
Returns all known filters- Returns:
- an unmodifiable map of filters
-
registerFilter
Register a new filter with the parser. If the filter is already registered, an IllegalArgumentException will be thrown.- Parameters:
name
- a name for the filterfilterClass
- fully qualified class name
-