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 SummaryFieldsModifier and TypeFieldDescriptionprivate static final org.slf4j.Loggerprivate static HashMap<ByteBuffer,Integer> 
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic booleancheckForAnd(byte[] filterStringAsByteArray, int indexOfAnd) Checks if the current index of filter string we are on is the beginning of the keyword 'AND'static booleancheckForOr(byte[] filterStringAsByteArray, int indexOfOr) Checks if the current index of filter string we are on is the beginning of the keyword 'OR'static booleancheckForSkip(byte[] filterStringAsByteArray, int indexOfSkip) Checks if the current index of filter string we are on is the beginning of the keyword 'SKIP'static booleancheckForWhile(byte[] filterStringAsByteArray, int indexOfWhile) Checks if the current index of filter string we are on is the beginning of the keyword 'WHILE'static booleanconvertByteArrayToBoolean(byte[] booleanAsByteArray) Converts a boolean expressed in a byte array to an actual booleanstatic intconvertByteArrayToInt(byte[] numberAsByteArray) Converts an int expressed in a byte array to an actual intstatic longconvertByteArrayToLong(byte[] numberAsByteArray) Converts a long expressed in a byte array to an actual longstatic ByteArrayComparablecreateComparator(byte[] comparator) Parses a comparator of the form comparatorType:comparatorValue form and returns a comparatorstatic CompareOperatorcreateCompareOperator(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 LanguagebooleanReturns which operator has higher precedencestatic booleanisQuoteUnescaped(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 FilterpopArguments(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 themvoidreduce(Stack<ByteBuffer> operatorStack, Stack<Filter> filterStack, ByteBuffer operator) This function is called while parsing the filterString and an operator is parsedstatic voidregisterFilter(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- 
ParseFilterpublic ParseFilter()
 
- 
- 
Method Details- 
parseFilterStringParses the filterString and constructs a filter using it- Parameters:
- filterString- filter string given by the user
- Returns:
- filter object we constructed
- Throws:
- CharacterCodingException
 
- 
parseFilterStringParses the filterString and constructs a filter using it- Parameters:
- filterStringAsByteArray- filter string given by the user
- Returns:
- filter object we constructed
- Throws:
- CharacterCodingException
 
- 
extractFilterSimpleExpressionpublic 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 user
- filterExpressionStartOffset- start index of the simple filter expression
- Returns:
- byte array containing the simple filter expression
- Throws:
- CharacterCodingException
 
- 
parseSimpleFilterExpressionpublic 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
 
- 
getFilterNameReturns the filter name given a simple filter expression- Parameters:
- filterStringAsByteArray- a simple filter expression
- Returns:
- name of filter in the simple filter expression
 
- 
getFilterArgumentsReturns 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
 
- 
reduceThis function is called while parsing the filterString and an operator is parsed- Parameters:
- operatorStack- the stack containing the operators and parenthesis
- filterStack- the stack containing the filters
- operator- the operator found while parsing the filterString
 
- 
popArgumentsPops 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 operators
- filterStack- the stack containing the filters
- Returns:
- the evaluated filter
 
- 
hasHigherPriorityReturns which operator has higher precedenceIf a has higher precedence than b, it returns true If they have the same precedence, it returns false 
- 
createUnescapdArgumentpublic 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 user
- argumentStartIndex- start index of the argument
- argumentEndIndex- end index of the argument
- Returns:
- returns an unescaped argument
 
- 
checkForOrpublic 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 user
- indexOfOr- index at which an 'O' was read
- Returns:
- true if the keyword 'OR' is at the current index
- Throws:
- CharacterCodingException
- ArrayIndexOutOfBoundsException
 
- 
checkForAndpublic 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 user
- indexOfAnd- index at which an 'A' was read
- Returns:
- true if the keyword 'AND' is at the current index
- Throws:
- CharacterCodingException
 
- 
checkForSkippublic 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 user
- indexOfSkip- index at which an 'S' was read
- Returns:
- true if the keyword 'SKIP' is at the current index
- Throws:
- CharacterCodingException
 
- 
checkForWhilepublic 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 user
- indexOfWhile- index at which an 'W' was read
- Returns:
- true if the keyword 'WHILE' is at the current index
- Throws:
- CharacterCodingException
 
- 
isQuoteUnescapedReturns a boolean indicating whether the quote was escaped or not- Parameters:
- array- byte array in which the quote was found
- quoteIndex- index of the single quote
- Returns:
- returns true if the quote was unescaped
 
- 
removeQuotesFromByteArrayTakes 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
 
- 
convertByteArrayToIntConverts 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_INTbytes available.- Parameters:
- numberAsByteArray- the int value expressed as a byte array
- Returns:
- the int value
 
- 
convertByteArrayToLongConverts 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_INTbytes available.- Parameters:
- numberAsByteArray- the long value expressed as a byte array
- Returns:
- the long value
 
- 
convertByteArrayToBooleanConverts 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
 
- 
createCompareOperatorTakes 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
 
- 
createComparatorParses 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
 
- 
parseComparatorSplits 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
 
- 
getSupportedFiltersReturn a Set of filters supported by the Filter Language
- 
getAllFiltersReturns all known filters- Returns:
- an unmodifiable map of filters
 
- 
registerFilterRegister a new filter with the parser. If the filter is already registered, an IllegalArgumentException will be thrown.- Parameters:
- name- a name for the filter
- filterClass- fully qualified class name
 
 
-