HBASE-8970 [book] Filter language documentation is hidden (Misty Stanley-Jones)

This commit is contained in:
Michael Stack 2014-05-27 08:43:25 -07:00
parent 56af657e5d
commit 856892cf57
3 changed files with 759 additions and 370 deletions

View File

@ -2425,6 +2425,7 @@ All the settings that apply to normal compactions (file size limits, etc.) apply
</chapter> <!-- architecture --> </chapter> <!-- architecture -->
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="external_apis.xml"/> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="external_apis.xml"/>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="thrift_filter_language.xml"/>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="cp.xml" /> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="cp.xml" />
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="performance.xml"/> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="performance.xml"/>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="troubleshooting.xml"/> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="troubleshooting.xml"/>

View File

@ -46,377 +46,9 @@
</para> </para>
</section> <!-- rest --> </section> <!-- rest -->
<section xml:id="thrift"> <section>
<title>Thrift</title> <title>Thrift</title>
<para>Currently most of the documentation on Thrift exists in the <para>Documentation about Thrift has moved to <xref linkend="thrift" />.</para>
<link xlink:href="http://wiki.apache.org/hadoop/Hbase/ThriftApi">Apache HBase Wiki on Thrift</link>.
</para>
<section xml:id="thrift.filter-language"><title>Filter Language</title>
<section xml:id="use-case"><title>Use Case</title>
<note>
<para>this feature was introduced in Apache HBase 0.92</para>
</note>
<para>This allows the user to perform server-side filtering when accessing HBase over Thrift (or in the shell -- see the 'scan' help in the shell).
The user specifies a filter via a string. The string is parsed on the server to construct the filter</para>
</section>
<section xml:id="general-syntax"><title>General Filter String Syntax</title>
<para>A simple filter expression is expressed as: <code>“FilterName (argument, argument, ... , argument)”</code></para>
<para>You must specify the name of the filter followed by the argument list in parenthesis. Commas separate the individual arguments</para>
<para>If the argument represents a string, it should be enclosed in single quotes.</para>
<para>If it represents a boolean, an integer or a comparison operator like &lt;,
>, != etc. it should not be enclosed in quotes</para>
<para>The filter name must be one word. All ASCII characters are allowed except for whitespace, single quotes and parenthesis.</para>
<para>The filters arguments can contain any ASCII character. <code>If single quotes are present in the argument, they must be escaped by a
preceding single quote</code></para>
</section>
<section xml:id="compound-filters-and-operators"><title>Compound Filters and Operators</title>
<para>Currently, two binary operators AND/OR and two unary operators WHILE/SKIP are supported.</para>
<para>Note: the operators are all in uppercase</para>
<para><emphasis role="bold">AND</emphasis> as the name suggests, if this
operator is used, the key-value must pass both the filters</para>
<para><emphasis role="bold">OR</emphasis> as the name suggests, if this operator
is used, the key-value must pass at least one of the filters</para>
<para><emphasis role="bold">SKIP</emphasis> For a particular row, if any of the
key-values dont pass the filter condition, the entire row is skipped</para>
<para><emphasis role="bold">WHILE</emphasis> - For a particular row, it continues
to emit key-values until a key-value is reached that fails the filter condition</para>
<para><emphasis role="bold">Compound Filters:</emphasis> Using these operators, a
hierarchy of filters can be created. For example: <code>“(Filter1 AND Filter2) OR (Filter3 AND Filter4)”</code></para>
</section>
<section xml:id="order-of-evaluation"><title>Order of Evaluation</title>
<para>Parenthesis have the highest precedence. The SKIP and WHILE operators are next and have the same precedence.The AND operator has the next highest precedence followed by the OR operator.</para>
<para>For example:</para>
<para>A filter string of the form:<code>“Filter1 AND Filter2 OR Filter3”</code>
will be evaluated as:<code>“(Filter1 AND Filter2) OR Filter3”</code></para>
<para>A filter string of the form:<code>“Filter1 AND SKIP Filter2 OR Filter3”</code>
will be evaluated as:<code>“(Filter1 AND (SKIP Filter2)) OR Filter3”</code></para>
</section>
<section xml:id="compare-operator"><title>Compare Operator</title>
<para>A compare operator can be any of the following:</para>
<orderedlist>
<listitem>
<para>LESS (&lt;)</para>
</listitem>
<listitem>
<para>LESS_OR_EQUAL (&lt;=)</para>
</listitem>
<listitem>
<para>EQUAL (=)</para>
</listitem>
<listitem>
<para>NOT_EQUAL (!=)</para>
</listitem>
<listitem>
<para>GREATER_OR_EQUAL (&gt;=)</para>
</listitem>
<listitem>
<para>GREATER (&gt;)</para>
</listitem>
<listitem>
<para>NO_OP (no operation)</para>
</listitem>
</orderedlist>
<para>The client should use the symbols (&lt;, &lt;=, =, !=, >, >=) to express
compare operators.</para>
</section>
<section xml:id="comparator"><title>Comparator</title>
<para>A comparator can be any of the following:</para>
<orderedlist>
<listitem>
<para><emphasis role="bold">BinaryComparator</emphasis> - This
lexicographically compares against the specified byte array using
Bytes.compareTo(byte[], byte[])</para>
</listitem>
<listitem>
<para><emphasis role="bold">BinaryPrefixComparator</emphasis> - This
lexicographically compares against a specified byte array. It only compares up to
the length of this byte array.</para>
</listitem>
<listitem>
<para><emphasis role="bold">RegexStringComparator</emphasis> - This compares
against the specified byte array using the given regular expression. Only EQUAL
and NOT_EQUAL comparisons are valid with this comparator</para>
</listitem>
<listitem>
<para><emphasis role="bold">SubStringComparator</emphasis> - This tests if
the given substring appears in a specified byte array. The comparison is case
insensitive. Only EQUAL and NOT_EQUAL comparisons are valid with this
comparator</para>
</listitem>
</orderedlist>
<para>The general syntax of a comparator is:<code> ComparatorType:ComparatorValue</code></para>
<para>The ComparatorType for the various comparators is as follows:</para>
<orderedlist>
<listitem>
<para><emphasis role="bold">BinaryComparator</emphasis> - binary</para>
</listitem>
<listitem>
<para><emphasis role="bold">BinaryPrefixComparator</emphasis> - binaryprefix</para>
</listitem>
<listitem>
<para><emphasis role="bold">RegexStringComparator</emphasis> - regexstring</para>
</listitem>
<listitem>
<para><emphasis role="bold">SubStringComparator</emphasis> - substring</para>
</listitem>
</orderedlist>
<para>The ComparatorValue can be any value.</para>
<para>Example1:<code> >, 'binary:abc' </code>will match everything that is lexicographically greater than "abc" </para>
<para>Example2:<code> =, 'binaryprefix:abc' </code>will match everything whose first 3 characters are lexicographically equal to "abc"</para>
<para>Example3:<code> !=, 'regexstring:ab*yz' </code>will match everything that doesn't begin with "ab" and ends with "yz"</para>
<para>Example4:<code> =, 'substring:abc123' </code>will match everything that begins with the substring "abc123"</para>
</section>
<section xml:id="examplePHPClientProgram"><title>Example PHP Client Program that uses the Filter Language</title>
<programlisting>
&lt;? $_SERVER['PHP_ROOT'] = realpath(dirname(__FILE__).'/..');
require_once $_SERVER['PHP_ROOT'].'/flib/__flib.php';
flib_init(FLIB_CONTEXT_SCRIPT);
require_module('storage/hbase');
$hbase = new HBase('&lt;server_name_running_thrift_server&gt;', &lt;port on which thrift server is running&gt;);
$hbase->open();
$client = $hbase->getClient();
$result = $client-&gt;scannerOpenWithFilterString('table_name', "(PrefixFilter ('row2') AND (QualifierFilter (&gt;=, 'binary:xyz'))) AND (TimestampsFilter ( 123, 456))");
$to_print = $client-&gt;scannerGetList($result,1);
while ($to_print) {
print_r($to_print);
$to_print = $client-&gt;scannerGetList($result,1);
}
$client-&gt;scannerClose($result);
?>
</programlisting>
</section>
<section xml:id="example-filter-strings"><title>Example Filter Strings</title>
<para>
<itemizedlist>
<listitem>
<para><code>“PrefixFilter (Row) AND PageFilter (1) AND FirstKeyOnlyFilter ()”</code> will return all key-value pairs that match the following conditions:</para>
<para>1) The row containing the key-value should have prefix “Row” </para>
<para>2) The key-value must be located in the first row of the table </para>
<para>3) The key-value pair must be the first key-value in the row </para>
</listitem>
</itemizedlist>
</para>
<orderedlist>
<listitem>
<itemizedlist>
<listitem>
<para><code>“(RowFilter (=, binary:Row 1) AND TimeStampsFilter (74689, 89734)) OR
ColumnRangeFilter (abc, true, xyz, false))”</code> will return all key-value pairs that match both the following conditions:</para>
<para>1) The key-value is in a row having row key “Row 1” </para>
<para>2) The key-value must have a timestamp of either 74689 or 89734.</para>
<para>Or it must match the following condition:</para>
<para>1) The key-value pair must be in a column that is lexicographically >= abc and &lt; xyz </para>
</listitem>
</itemizedlist>
</listitem>
</orderedlist>
<para>
<itemizedlist>
<listitem>
<para><code>“SKIP ValueFilter (0)”</code> will skip the entire row if any of the values in the row is not 0</para>
</listitem>
</itemizedlist>
</para>
</section>
<section xml:id="IndividualFilterSyntax"><title>Individual Filter Syntax</title>
<orderedlist>
<listitem>
<para><emphasis role="bold"><emphasis role="underline">KeyOnlyFilter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter doesnt take any
arguments. It returns only the key component of each key-value. </para>
<para><emphasis role="bold">Syntax:</emphasis> KeyOnlyFilter () </para>
<para><emphasis role="bold">Example:</emphasis> "KeyOnlyFilter ()"</para>
</listitem>
<listitem>
<para><emphasis role="bold"><emphasis role="underline">FirstKeyOnlyFilter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter doesnt take any
arguments. It returns only the first key-value from each row. </para>
<para><emphasis role="bold">Syntax:</emphasis> FirstKeyOnlyFilter () </para>
<para><emphasis role="bold">Example:</emphasis> "FirstKeyOnlyFilter ()" </para>
</listitem>
<listitem>
<para><emphasis role="bold"><emphasis role="underline">PrefixFilter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter takes one argument a prefix of a
row key. It returns only those key-values present in a row that starts with the
specified row prefix</para>
<para><emphasis role="bold">Syntax:</emphasis> PrefixFilter (&lt;row_prefix>) </para>
<para><emphasis role="bold">Example:</emphasis> "PrefixFilter (Row)" </para>
</listitem>
<listitem>
<para><emphasis role="bold"><emphasis role="underline">
ColumnPrefixFilter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter takes one argument
a column prefix. It returns only those key-values present in a column that starts
with the specified column prefix. The column prefix must be of the form: <code>“qualifier” </code></para>
<para><emphasis role="bold">Syntax:</emphasis>ColumnPrefixFilter(&lt;column_prefix>)</para>
<para><emphasis role="bold">Example:</emphasis> "ColumnPrefixFilter(Col)"</para>
</listitem>
<listitem>
<para><emphasis role="underline"><emphasis role="bold">MultipleColumnPrefixFilter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter takes a list of
column prefixes. It returns key-values that are present in a column that starts with
any of the specified column prefixes. Each of the column prefixes must be of the form: <code>“qualifier”</code></para>
<para><emphasis role="bold">Syntax:</emphasis>MultipleColumnPrefixFilter(&lt;column_prefix>, &lt;column_prefix>, …, &lt;column_prefix>)</para>
<para><emphasis role="bold">Example:</emphasis> "MultipleColumnPrefixFilter(Col1, Col2)" </para>
</listitem>
<listitem>
<para><emphasis role="bold"><emphasis role="underline">ColumnCountGetFilter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter takes one argument
a limit. It returns the first limit number of columns in the table</para>
<para><emphasis role="bold">Syntax:</emphasis> ColumnCountGetFilter (&lt;limit>)</para>
<para><emphasis role="bold">Example:</emphasis> "ColumnCountGetFilter (4)"</para>
</listitem>
<listitem>
<para><emphasis role="bold"><emphasis role="underline">PageFilter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter takes one argument
a page size. It returns page size number of rows from the table. </para>
<para><emphasis role="bold">Syntax:</emphasis> PageFilter (&lt;page_size>)</para>
<para><emphasis role="bold">Example:</emphasis> "PageFilter (2)" </para>
</listitem>
<listitem>
<para><emphasis role="bold"><emphasis role="underline">ColumnPaginationFilter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter takes two
arguments a limit and offset. It returns limit number of columns after offset number
of columns. It does this for all the rows</para>
<para><emphasis role="bold">Syntax:</emphasis> ColumnPaginationFilter(&lt;limit>,
&lt;offset>) </para>
<para><emphasis role="bold">Example:</emphasis> "ColumnPaginationFilter (3, 5)" </para>
</listitem>
<listitem>
<para><emphasis role="bold"><emphasis role="underline">InclusiveStopFilter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter takes one argument
a row key on which to stop scanning. It returns all key-values present in rows up to
and including the specified row</para>
<para><emphasis role="bold">Syntax:</emphasis> InclusiveStopFilter(&lt;stop_row_key>) </para>
<para><emphasis role="bold">Example:</emphasis> "InclusiveStopFilter ('Row2')" </para>
</listitem>
<listitem>
<para><emphasis role="bold"><emphasis role="underline">TimeStampsFilter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter takes a list of
timestamps. It returns those key-values whose timestamps matches any of the specified
timestamps</para>
<para> <emphasis role="bold">Syntax:</emphasis> TimeStampsFilter (&lt;timestamp>, &lt;timestamp>, ... ,&lt;timestamp>) </para>
<para> <emphasis role="bold">Example:</emphasis> "TimeStampsFilter (5985489, 48895495, 58489845945)"</para>
</listitem>
<listitem>
<para><emphasis role="bold"><emphasis role="underline">RowFilter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter takes a compare
operator and a comparator. It compares each row key with the comparator using the
compare operator and if the comparison returns true, it returns all the key-values in
that row</para>
<para><emphasis role="bold">Syntax:</emphasis> RowFilter (&lt;compareOp>, &lt;row_comparator>) </para>
<para><emphasis role="bold">Example: </emphasis>"RowFilter (&lt;=, xyz)" </para>
</listitem>
<listitem>
<para><emphasis role="bold"><emphasis role="underline">Family Filter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter takes a compare
operator and a comparator. It compares each qualifier name with the comparator using
the compare operator and if the comparison returns true, it returns all the key-values
in that column</para>
<para><emphasis role="bold">Syntax:</emphasis> QualifierFilter (&lt;compareOp&gt;, &lt;qualifier_comparator>) </para>
<para><emphasis role="bold">Example:</emphasis> "QualifierFilter (=, Column1)"</para>
</listitem>
<listitem>
<para><emphasis role="bold"><emphasis role="underline">QualifierFilter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter takes a compare
operator and a comparator. It compares each qualifier name with the comparator using
the compare operator and if the comparison returns true, it returns all the key-values
in that column</para>
<para><emphasis role="bold">Syntax:</emphasis> QualifierFilter (&lt;compareOp>,&lt;qualifier_comparator>) </para>
<para><emphasis role="bold">Example:</emphasis> "QualifierFilter (=,Column1)"</para>
</listitem>
<listitem>
<para><emphasis role="bold"><emphasis role="underline">ValueFilter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter takes a compare operator and a
comparator. It compares each value with the comparator using the compare operator and
if the comparison returns true, it returns that key-value</para>
<para><emphasis role="bold">Syntax:</emphasis> ValueFilter (&lt;compareOp>,&lt;value_comparator>) </para>
<para><emphasis role="bold">Example:</emphasis> "ValueFilter (!=, Value)" </para>
</listitem>
<listitem>
<para><emphasis role="bold"><emphasis role="underline">DependentColumnFilter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter takes two arguments a family
and a qualifier. It tries to locate this column in each row and returns all key-values
in that row that have the same timestamp. If the row doesnt contain the specified
column none of the key-values in that row will be returned.</para>
<para>The filter can also take an optional boolean argument dropDependentColumn. If set to true, the column we were depending on doesnt get returned.</para>
<para>The filter can also take two more additional optional arguments a compare operator and a value comparator, which are further checks in addition to the family and qualifier. If the dependent column is found, its value should also pass the value check and then only is its timestamp taken into consideration</para>
<para><emphasis role="bold">Syntax:</emphasis> DependentColumnFilter (&lt;family>, &lt;qualifier>, &lt;boolean>, &lt;compare operator>, &lt;value comparator)</para>
<para><emphasis role="bold">Syntax:</emphasis> DependentColumnFilter (&lt;family>, &lt;qualifier>, &lt;boolean>) </para>
<para><emphasis role="bold">Syntax:</emphasis> DependentColumnFilter (&lt;family>, &lt;qualifier>) </para>
<para><emphasis role="bold">Example:</emphasis> "DependentColumnFilter (conf, blacklist, false, >=, zebra)" </para>
<para><emphasis role="bold">Example:</emphasis> "DependentColumnFilter (conf, 'blacklist', true)"</para>
<para><emphasis role="bold">Example:</emphasis> "DependentColumnFilter (conf, 'blacklist')"</para>
</listitem>
<listitem>
<para><emphasis role="bold"><emphasis role="underline">SingleColumnValueFilter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter takes a column family, a
qualifier, a compare operator and a comparator. If the specified column is not found
all the columns of that row will be emitted. If the column is found and the comparison
with the comparator returns true, all the columns of the row will be emitted. If the
condition fails, the row will not be emitted. </para>
<para>This filter also takes two additional optional boolean arguments filterIfColumnMissing and setLatestVersionOnly</para>
<para>If the filterIfColumnMissing flag is set to true the columns of the row will not be emitted if the specified column to check is not found in the row. The default value is false.</para>
<para>If the setLatestVersionOnly flag is set to false, it will test previous versions (timestamps) too. The default value is true.</para>
<para>These flags are optional and if you must set neither or both</para>
<para><emphasis role="bold">Syntax:</emphasis> SingleColumnValueFilter(&lt;family>, &lt;qualifier>, &lt;compare operator>, &lt;comparator>, &lt;filterIfColumnMissing_boolean>, &lt;latest_version_boolean>) </para>
<para><emphasis role="bold">Syntax:</emphasis> SingleColumnValueFilter(&lt;family>, &lt;qualifier>, &lt;compare operator>, &lt;comparator>) </para>
<para><emphasis role="bold">Example:</emphasis> "SingleColumnValueFilter (FamilyA, Column1, &lt;=, abc, true, false)" </para>
<para><emphasis role="bold">Example:</emphasis> "SingleColumnValueFilter (FamilyA, Column1, &lt;=, abc)" </para>
</listitem>
<listitem>
<para><emphasis role="bold"><emphasis role="underline">SingleColumnValueExcludeFilter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter takes the same arguments and
behaves same as SingleColumnValueFilter however, if the column is found and the
condition passes, all the columns of the row will be emitted except for the tested
column value. </para>
<para><emphasis role="bold">Syntax:</emphasis> SingleColumnValueExcludeFilter('&lt;family>', '&lt;qualifier>', &lt;compare operator>, '&lt;comparator>', &lt;latest_version_boolean>, &lt;filterIfColumnMissing_boolean>)</para>
<para><emphasis role="bold">Syntax:</emphasis> SingleColumnValueExcludeFilter('&lt;family>', '&lt;qualifier>', &lt;compare operator>, '&lt;comparator>') </para>
<para><emphasis role="bold">Example:</emphasis> "SingleColumnValueExcludeFilter (FamilyA, Column1, &lt;=, abc, false, true)"</para>
<para><emphasis role="bold">Example:</emphasis> "SingleColumnValueExcludeFilter (FamilyA, Column1, &lt;=, abc)" </para>
</listitem>
<listitem>
<para><emphasis role="bold"><emphasis role="underline">ColumnRangeFilter</emphasis></emphasis></para>
<para><emphasis role="bold">Description:</emphasis> This filter is used for selecting only those
keys with columns that are between minColumn and maxColumn. It also takes two boolean
variables to indicate whether to include the minColumn and maxColumn or not.</para>
<para>If you dont want to set the minColumn or the maxColumn you can pass in an empty argument.</para>
<para><emphasis role="bold">Syntax:</emphasis> ColumnRangeFilter (&lt;minColumn>, &lt;minColumnInclusive_bool>, &lt;maxColumn>, &lt;maxColumnInclusive_bool>)</para>
<para><emphasis role="bold">Example:</emphasis> "ColumnRangeFilter (abc, true, xyz, false)"</para>
</listitem>
</orderedlist>
</section>
</section>
</section> <!-- thrift --> </section> <!-- thrift -->
<section xml:id="c"> <section xml:id="c">

View File

@ -0,0 +1,756 @@
<?xml version="1.0" encoding="UTF-8"?>
<chapter version="5.0" xml:id="thrift"
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:m="http://www.w3.org/1998/Math/MathML"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:db="http://docbook.org/ns/docbook">
<!--
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<title>Thrift API and Filter Language</title>
<para>Apache <link
xlink:href="http://thrift.apache.org/">Thrift</link> is a cross-platform, cross-language
development framework. HBase includes a Thrift API and filter language. The Thrift API
relies on client and server processes. Documentation about the HBase Thrift API is located
at <link
xlink:href="http://wiki.apache.org/hadoop/Hbase/ThriftApi" />. The rest of this chapter
discusses the filter language provided by the Thrift API.</para>
<section
xml:id="thrift.filter-language">
<title>Filter Language</title>
<para
xml:id="use-case">Thrift Filter Language was introduced in APache HBase 0.92. It allows
you to perform server-side filtering when accessing HBase over Thrift or in the HBase
shell. You can find out more about shell integration by using the <code>scan help</code>
command in the shell.</para>
<para>You specify a filter as a string, which is parsed on the server to construct the
filter.</para>
<section
xml:id="general-syntax">
<title>General Filter String Syntax</title>
<para>A simple filter expression is expressed as a string:</para>
<screen>“FilterName (argument, argument,... , argument)”</screen>
<para>Keep the following syntax guidelines in mind.</para>
<itemizedlist>
<listitem>
<para>Specify the name of the filter followed by the comma-separated argument
list in parentheses.</para>
</listitem>
<listitem>
<para>If the argument represents a string, it should be enclosed in single
quotes (<literal>'</literal>).</para>
</listitem>
<listitem>
<para>Arguments which represent a boolean, an integer, or a comparison operator
(such as &lt;, &gt;, or !=), should not be enclosed in quotes</para>
</listitem>
<listitem>
<para>The filter name must be a single word. All ASCII characters are allowed
except for whitespace, single quotes and parentheses.</para>
</listitem>
<listitem>
<para>The filters arguments can contain any ASCII character. If single quotes
are present in the argument, they must be escaped by an additional preceding
single quote.</para>
</listitem>
</itemizedlist>
</section>
<section
xml:id="compound-filters-and-operators">
<title>Compound Filters and Operators</title>
<variablelist>
<title>Binary Operators</title>
<varlistentry>
<term><code>AND</code></term>
<listitem><para>If the <code>AND</code> operator is used, the key-vallue
must satisfy both the filters.</para></listitem>
</varlistentry>
<varlistentry>
<term><code>OR</code></term>
<listitem><para>If the <code>OR</code> operator is used, the key-value
must satisfy at least one of the filters.</para></listitem>
</varlistentry>
</variablelist>
<variablelist>
<title>Unary Operators</title>
<varlistentry>
<term><code>SKIP</code></term>
<listitem><para>For a particular row, if any of the key-values fail the
filter condition, the entire row is skipped.</para></listitem>
</varlistentry>
<varlistentry>
<term><code>WHILE</code></term>
<listitem><para>For a particular row, key-values will be emitted until a
key-value is reached t hat fails the filter condition.</para></listitem>
</varlistentry>
</variablelist>
<example>
<title>Compound Operators</title>
<para>You can combine multiple operators to create a hierarchy of filters, such as
the following example:</para>
<programlisting>(Filter1 AND Filter2) OR (Filter3 AND Filter4)</programlisting>
</example>
</section>
<section
xml:id="order-of-evaluation">
<title>Order of Evaluation</title>
<orderedlist>
<listitem><para>Parentheses have the highest precedence.</para></listitem>
<listitem><para>The unary operators <code>SKIP</code> and <code>WHILE</code> are next, and have the same
precedence.</para></listitem>
<listitem><para>The binary operators follow. <code>AND</code> has highest
precedence, followed by <code>OR</code>.</para></listitem>
</orderedlist>
<example>
<title>Precedence Example</title>
<programlisting><userinput>Filter1 AND Filter2 OR Filter</userinput>
is evaluated as
<userinput>(Filter1 AND Filter2) OR Filter3</userinput></programlisting>
<programlisting><userinput>Filter1 AND SKIP Filter2 OR Filter3</userinput>
is evaluated as
<userinput>(Filter1 AND (SKIP Filter2)) OR Filter3</userinput></programlisting>
</example>
<para>You can use parentheses to explicitly control the order of evaluation.</para>
</section>
<section
xml:id="compare-operator">
<title>Compare Operator</title>
<para>The following compare operators are provided:</para>
<orderedlist>
<listitem>
<para>LESS (&lt;)</para>
</listitem>
<listitem>
<para>LESS_OR_EQUAL (&lt;=)</para>
</listitem>
<listitem>
<para>EQUAL (=)</para>
</listitem>
<listitem>
<para>NOT_EQUAL (!=)</para>
</listitem>
<listitem>
<para>GREATER_OR_EQUAL (&gt;=)</para>
</listitem>
<listitem>
<para>GREATER (&gt;)</para>
</listitem>
<listitem>
<para>NO_OP (no operation)</para>
</listitem>
</orderedlist>
<para>The client should use the symbols (&lt;, &lt;=, =, !=, &gt;, &gt;=) to express compare
operators.</para>
</section>
<section
xml:id="comparator">
<title>Comparator</title>
<para>A comparator can be any of the following:</para>
<orderedlist>
<listitem>
<para><emphasis
role="bold">BinaryComparator</emphasis> - This lexicographically
compares against the specified byte array using Bytes.compareTo(byte[],
byte[])</para>
</listitem>
<listitem>
<para><emphasis
role="bold">BinaryPrefixComparator</emphasis> - This lexicographically
compares against a specified byte array. It only compares up to the length
of this byte array.</para>
</listitem>
<listitem>
<para><emphasis
role="bold">RegexStringComparator</emphasis> - This compares against the
specified byte array using the given regular expression. Only EQUAL and
NOT_EQUAL comparisons are valid with this comparator</para>
</listitem>
<listitem>
<para><emphasis
role="bold">SubStringComparator</emphasis> - This tests if the given
substring appears in a specified byte array. The comparison is case
insensitive. Only EQUAL and NOT_EQUAL comparisons are valid with this
comparator</para>
</listitem>
</orderedlist>
<para>The general syntax of a comparator is:<code>
ComparatorType:ComparatorValue</code></para>
<para>The ComparatorType for the various comparators is as follows:</para>
<orderedlist>
<listitem>
<para><emphasis
role="bold">BinaryComparator</emphasis> - binary</para>
</listitem>
<listitem>
<para><emphasis
role="bold">BinaryPrefixComparator</emphasis> - binaryprefix</para>
</listitem>
<listitem>
<para><emphasis
role="bold">RegexStringComparator</emphasis> - regexstring</para>
</listitem>
<listitem>
<para><emphasis
role="bold">SubStringComparator</emphasis> - substring</para>
</listitem>
</orderedlist>
<para>The ComparatorValue can be any value.</para>
<example>
<title>Example 1</title>
<para><code> >, 'binary:abc' </code>will match everything that is
lexicographically greater than "abc" </para>
</example>
<example>
<title>Example 2</title>
<para><code> =, 'binaryprefix:abc' </code>will match everything whose first 3
characters are lexicographically equal to "abc"</para>
</example>
<example>
<title>Example 3</title>
<para><code> !=, 'regexstring:ab*yz' </code>will match everything that doesn't
begin with "ab" and ends with "yz"</para>
</example>
<example>
<title>Example 4</title>
<para><code> =, 'substring:abc123' </code>will match everything that begins
with the substring "abc123"</para>
</example>
</section>
<section
xml:id="examplePHPClientProgram">
<title>Example PHP Client Program that uses the Filter Language</title>
<programlisting language="PHP" role="PHP"><![CDATA[
<? $_SERVER['PHP_ROOT'] = realpath(dirname(__FILE__).'/..');
require_once $_SERVER['PHP_ROOT'].'/flib/__flib.php';
flib_init(FLIB_CONTEXT_SCRIPT);
require_module('storage/hbase');
$hbase = new HBase('<server_name_running_thrift_server>', <port on which thrift server is running>);
$hbase->open();
$client = $hbase->getClient();
$result = $client->scannerOpenWithFilterString('table_name', "(PrefixFilter ('row2') AND (QualifierFilter (>=, 'binary:xyz'))) AND (TimestampsFilter ( 123, 456))");
$to_print = $client->scannerGetList($result,1);
while ($to_print) {
print_r($to_print);
$to_print = $client->scannerGetList($result,1);
}
$client->scannerClose($result);
?>
]]></programlisting>
</section>
<section
xml:id="example-filter-strings">
<title>Example Filter Strings</title>
<para>
<itemizedlist>
<listitem>
<para><code>“PrefixFilter (Row) AND PageFilter (1) AND FirstKeyOnlyFilter
()”</code> will return all key-value pairs that match the following
conditions:</para>
<orderedlist>
<listitem>
<para>The row containing the key-value should have prefix “Row”
</para>
</listitem>
<listitem>
<para>The key-value must be located in the first row of the table
</para>
</listitem>
<listitem>
<para>The key-value pair must be the first key-value in the row
</para>
</listitem>
</orderedlist>
</listitem>
</itemizedlist>
</para>
<orderedlist>
<listitem>
<itemizedlist>
<listitem>
<para><code>“(RowFilter (=, binary:Row 1) AND TimeStampsFilter (74689,
89734)) OR ColumnRangeFilter (abc, true, xyz,
false))”</code> will return all key-value pairs that match both
the following conditions:</para>
<itemizedlist>
<listitem>
<para>The key-value is in a row having row key “Row 1” </para>
</listitem>
<listitem>
<para>The key-value must have a timestamp of either 74689 or
89734.</para>
</listitem>
<listitem>
<para>Or it must match the following condition:</para>
<itemizedlist>
<listitem>
<para>The key-value pair must be in a column that is
lexicographically >= abc and &lt; xyz </para>
</listitem>
</itemizedlist>
</listitem>
</itemizedlist>
</listitem>
</itemizedlist>
</listitem>
</orderedlist>
<para>
<itemizedlist>
<listitem>
<para><code>“SKIP ValueFilter (0)”</code> will skip the entire row if any of
the values in the row is not 0</para>
</listitem>
</itemizedlist>
</para>
</section>
<section
xml:id="IndividualFilterSyntax">
<title>Individual Filter Syntax</title>
<variablelist>
<varlistentry>
<term>KeyOnlyFilter</term>
<listitem>
<para>This filter doesnt take any arguments. It returns only the key
component of each key-value.</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting>KeyOnlyFilter ()</programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>KeyOnlyFilter ()"</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>FirstKeyOnlyFilter</term>
<listitem>
<para>This filter doesnt take any arguments. It returns only the first
key-value from each row.</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting>FirstKeyOnlyFilter ()</programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>FirstKeyOnlyFilter ()</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>PrefixFilter</term>
<listitem>
<para>This filter takes one argument a prefix of a row key. It returns
only those key-values present in a row that starts with the specified
row prefix</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting>PrefixFilter (&lt;row_prefix>)</programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>PrefixFilter (Row)</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>ColumnPrefixFilter</term>
<listitem>
<para>This filter takes one argument a column prefix. It returns only
those key-values present in a column that starts with the specified
column prefix. The column prefix must be of the form:
<code>“qualifier”</code>.</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting>ColumnPrefixFilter(&lt;column_prefix>)</programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>ColumnPrefixFilter(Col)</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>MultipleColumnPrefixFilter</term>
<listitem>
<para>This filter takes a list of column prefixes. It returns key-values
that are present in a column that starts with any of the specified
column prefixes. Each of the column prefixes must be of the form:
<code>“qualifier”</code>.</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting>MultipleColumnPrefixFilter(&lt;column_prefix>, &lt;column_prefix>, …, &lt;column_prefix>)</programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>MultipleColumnPrefixFilter(Col1, Col2)</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>ColumnCountGetFilter</term>
<listitem>
<para>This filter takes one argument a limit. It returns the first limit
number of columns in the table.</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting>ColumnCountGetFilter
(&lt;limit>)</programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>ColumnCountGetFilter (4)</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>PageFilter</term>
<listitem>
<para>This filter takes one argument a page size. It returns page size
number of rows from the table.</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting>PageFilter (&lt;page_size&gt;)</programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>PageFilter (2)</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>ColumnPaginationFilter</term>
<listitem>
<para>This filter takes two arguments a limit and offset. It returns limit
number of columns after offset number of columns. It does this for all
the rows.</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting>ColumnPaginationFilter(&lt;limit>, &lt;offset>)</programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>ColumnPaginationFilter (3, 5)</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>InclusiveStopFilter</term>
<listitem>
<para>This filter takes one argument a row key on which to stop scanning.
It returns all key-values present in rows up to and including the
specified row.</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting>InclusiveStopFilter(&lt;stop_row_key>)</programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>InclusiveStopFilter ('Row2')</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>TimeStampsFilter</term>
<listitem>
<para>This filter takes a list of timestamps. It returns those key-values
whose timestamps matches any of the specified timestamps.</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting>TimeStampsFilter (&lt;timestamp>, &lt;timestamp>, ... ,&lt;timestamp>)</programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>TimeStampsFilter (5985489, 48895495, 58489845945)</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>RowFilter</term>
<listitem>
<para>This filter takes a compare operator and a comparator. It compares
each row key with the comparator using the compare operator and if the
comparison returns true, it returns all the key-values in that
row.</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting>RowFilter (&lt;compareOp>, &lt;row_comparator>)</programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>RowFilter (&lt;=, xyz)</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>Family Filter</term>
<listitem>
<para>This filter takes a compare operator and a comparator. It compares
each qualifier name with the comparator using the compare operator and
if the comparison returns true, it returns all the key-values in that
column.</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting>QualifierFilter (&lt;compareOp&gt;, &lt;qualifier_comparator>)</programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>QualifierFilter (=, Column1)</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>QualifierFilter</term>
<listitem>
<para>This filter takes a compare operator and a comparator. It compares
each qualifier name with the comparator using the compare operator and
if the comparison returns true, it returns all the key-values in that
column.</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting>QualifierFilter (&lt;compareOp>,&lt;qualifier_comparator>)</programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>QualifierFilter (=,Column1)</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>ValueFilter</term>
<listitem>
<para>This filter takes a compare operator and a comparator. It compares
each value with the comparator using the compare operator and if the
comparison returns true, it returns that key-value.</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting>ValueFilter (&lt;compareOp>,&lt;value_comparator>) </programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>ValueFilter (!=, Value)</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>DependentColumnFilter</term>
<listitem>
<para>This filter takes two arguments a family and a qualifier. It tries
to locate this column in each row and returns all key-values in that row
that have the same timestamp. If the row doesnt contain the specified
column none of the key-values in that row will be returned.</para>
<para>The filter can also take an optional boolean argument
dropDependentColumn. If set to true, the column we were depending on
doesnt get returned.</para>
<para>The filter can also take two more additional optional arguments a
compare operator and a value comparator, which are further checks in
addition to the family and qualifier. If the dependent column is found,
its value should also pass the value check and then only is its
timestamp taken into consideration.</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting><![CDATA[DependentColumnFilter (<family>,<qualifier>, <boolean>, <compare operator>, <value
comparator)]]></programlisting>
</listitem>
<listitem>
<programlisting><![CDATA[DependentColumnFilter (<family>,<qualifier>, <boolean>)]]></programlisting>
</listitem>
<listitem>
<programlisting>DependentColumnFilter (&lt;family>,&lt;qualifier>)</programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>DependentColumnFilter (conf, blacklist, false, >=, zebra)</programlisting>
</listitem>
<listitem>
<programlisting>DependentColumnFilter (conf, 'blacklist', true)</programlisting>
</listitem>
<listitem>
<programlisting>DependentColumnFilter (conf, 'blacklist')</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>SingleColumnValueFilter</term>
<listitem>
<para>This filter takes a column family, a qualifier, a compare operator and
a comparator. If the specified column is not found all the columns of
that row will be emitted. If the column is found and the comparison with
the comparator returns true, all the columns of the row will be emitted.
If the condition fails, the row will not be emitted. </para>
<para>This filter also takes two additional optional boolean arguments
filterIfColumnMissing and setLatestVersionOnly</para>
<para>If the filterIfColumnMissing flag is set to true the columns of the
row will not be emitted if the specified column to check is not found in
the row. The default value is false.</para>
<para>If the setLatestVersionOnly flag is set to false, it will test
previous versions (timestamps) too. The default value is true.</para>
<para>These flags are optional and if you must set neither or both.</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting>SingleColumnValueFilter(&lt;family>,&lt;qualifier>, &lt;compare operator>, &lt;comparator>, &lt;filterIfColumnMissing_boolean>, &lt;latest_version_boolean>)</programlisting>
</listitem>
<listitem>
<programlisting>SingleColumnValueFilter(&lt;family>, &lt;qualifier>, &lt;compare operator>, &lt;comparator>)</programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>SingleColumnValueFilter (FamilyA, Column1, &lt;=, abc, true, false)</programlisting>
</listitem>
<listitem>
<programlisting>SingleColumnValueFilter (FamilyA, Column1, &lt;=, abc)</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>SingleColumnValueExcludeFilter</term>
<listitem>
<para>This filter takes the same arguments and behaves same as
SingleColumnValueFilter however, if the column is found and the
condition passes, all the columns of the row will be emitted except for
the tested column value.</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting>SingleColumnValueExcludeFilter('&lt;family>', '&lt;qualifier>', &lt;compare operator>, '&lt;comparator>', &lt;latest_version_boolean>, &lt;filterIfColumnMissing_boolean>)</programlisting>
</listitem>
<listitem>
<programlisting>SingleColumnValueExcludeFilter('&lt;family>', '&lt;qualifier>', &lt;compare operator>, '&lt;comparator>')</programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>SingleColumnValueExcludeFilter (FamilyA, Column1, &lt;=, abc, false, true)</programlisting>
</listitem>
<listitem>
<programlisting>SingleColumnValueExcludeFilter (FamilyA, Column1, &lt;=, abc)</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>ColumnRangeFilter</term>
<listitem>
<para>This filter is used for selecting only those keys with columns that
are between minColumn and maxColumn. It also takes two boolean variables
to indicate whether to include the minColumn and maxColumn or
not.</para>
<para>If you dont want to set the minColumn or the maxColumn you can pass
in an empty argument.</para>
<itemizedlist>
<title>Syntax</title>
<listitem>
<programlisting>ColumnRangeFilter (&lt;minColumn>, &lt;minColumnInclusive_bool>, &lt;maxColumn>, &lt;maxColumnInclusive_bool>)</programlisting>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Example</title>
<listitem>
<programlisting>ColumnRangeFilter (abc, true, xyz, false)</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
</variablelist>
</section>
</section>
</chapter>