org.apache.hadoop.hbase.filter
Class ParseFilter

java.lang.Object
  extended by org.apache.hadoop.hbase.filter.ParseFilter

@InterfaceAudience.Public
@InterfaceStability.Stable
public class ParseFilter
extends Object

This class allows a user to specify a filter via a string The string is parsed using the methods of this class and a filter object is constructed. This filter object is then wrapped in a scanner object which is then returned

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


Constructor Summary
ParseFilter()
           
 
Method Summary
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)
          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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParseFilter

public ParseFilter()
Method Detail

parseFilterString

public Filter parseFilterString(String filterString)
                         throws CharacterCodingException
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

public Filter parseFilterString(byte[] filterStringAsByteArray)
                         throws CharacterCodingException
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 user

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

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

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

public static byte[] getFilterName(byte[] filterStringAsByteArray)
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

public static ArrayList<byte[]> getFilterArguments(byte[] filterStringAsByteArray)
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

public void reduce(Stack<ByteBuffer> operatorStack,
                   Stack<Filter> filterStack,
                   ByteBuffer operator)
This 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

popArguments

public 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

Parameters:
operatorStack - the stack containing the operators
filterStack - the stack containing the filters
Returns:
the evaluated filter

hasHigherPriority

public boolean hasHigherPriority(ByteBuffer a,
                                 ByteBuffer b)
Returns which operator has higher precedence

If 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 user
argumentStartIndex - start index of the argument
argumentEndIndex - 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 user
indexOfOr - 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 user
indexOfAnd - 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 user
indexOfSkip - 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 user
indexOfWhile - index at which an 'W' was read
Returns:
true if the keyword 'WHILE' is at the current index
Throws:
CharacterCodingException

isQuoteUnescaped

public static boolean isQuoteUnescaped(byte[] array,
                                       int quoteIndex)
Returns 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

removeQuotesFromByteArray

public 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

Parameters:
quotedByteArray - the quoted byte array
Returns:
Unquoted byte array

convertByteArrayToInt

public static int convertByteArrayToInt(byte[] numberAsByteArray)
Converts an int expressed in a byte array to an actual int

This 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

public static long convertByteArrayToLong(byte[] numberAsByteArray)
Converts a long expressed in a byte array to an actual long

This 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

public static boolean convertByteArrayToBoolean(byte[] booleanAsByteArray)
Converts a boolean expressed in a byte array to an actual boolean

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

Parameters:
booleanAsByteArray - the boolean value expressed as a byte array
Returns:
the boolean value

createCompareOp

public static CompareFilter.CompareOp createCompareOp(byte[] compareOpAsByteArray)
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

public static ByteArrayComparable createComparator(byte[] comparator)
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

public static byte[][] parseComparator(byte[] comparator)
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

public Set<String> getSupportedFilters()
Return a Set of filters supported by the Filter Language


getAllFilters

public static Map<String,String> getAllFilters()
Returns all known filters

Returns:
an unmodifiable map of filters

registerFilter

public static void registerFilter(String name,
                                  String filterClass)
Register 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


Copyright © 2007–2016 The Apache Software Foundation. All rights reserved.