|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.hadoop.hbase.filter.ParseFilter
public class ParseFilter
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 documentaton 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 WritableByteArrayComparable |
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 |
---|
public ParseFilter()
Method Detail |
---|
public Filter parseFilterString(String filterString) throws CharacterCodingException
filterString
- filter string given by the user
CharacterCodingException
public Filter parseFilterString(byte[] filterStringAsByteArray) throws CharacterCodingException
filterStringAsByteArray
- filter string given by the user
CharacterCodingException
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 expression
CharacterCodingException
public Filter parseSimpleFilterExpression(byte[] filterStringAsByteArray) throws CharacterCodingException
filterStringAsByteArray
- filter string given by the user
CharacterCodingException
public static byte[] getFilterName(byte[] filterStringAsByteArray)
filterStringAsByteArray
- a simple filter expression
public static ArrayList<byte[]> getFilterArguments(byte[] filterStringAsByteArray)
filterStringAsByteArray
- filter string given by the user
public 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 filters
public 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 argument
public static boolean checkForOr(byte[] filterStringAsByteArray, int indexOfOr) throws CharacterCodingException, ArrayIndexOutOfBoundsException
filterStringAsByteArray
- filter string given by the userindexOfOr
- index at which an 'O' was read
CharacterCodingException
ArrayIndexOutOfBoundsException
public static boolean checkForAnd(byte[] filterStringAsByteArray, int indexOfAnd) throws CharacterCodingException
filterStringAsByteArray
- filter string given by the userindexOfAnd
- index at which an 'A' was read
CharacterCodingException
public static boolean checkForSkip(byte[] filterStringAsByteArray, int indexOfSkip) throws CharacterCodingException
filterStringAsByteArray
- filter string given by the userindexOfSkip
- index at which an 'S' was read
CharacterCodingException
public static boolean checkForWhile(byte[] filterStringAsByteArray, int indexOfWhile) throws CharacterCodingException
filterStringAsByteArray
- filter string given by the userindexOfWhile
- index at which an 'W' was read
CharacterCodingException
public static boolean isQuoteUnescaped(byte[] array, int quoteIndex)
array
- byte array in which the quote was foundquoteIndex
- index of the single quote
public static byte[] removeQuotesFromByteArray(byte[] quotedByteArray)
quotedByteArray
- the quoted byte array
public 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 array
public 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 array
public 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 array
public static CompareFilter.CompareOp createCompareOp(byte[] compareOpAsByteArray)
compareOpAsByteArray
- the comparatorOperator symbol as a byte array
public static WritableByteArrayComparable createComparator(byte[] comparator)
comparator
- the comparator in the form comparatorType:comparatorValue
public static byte[][] parseComparator(byte[] comparator)
comparator
- the comparator
public 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 name
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |