HBase Filter Language in PHP with Thrift

2019-06-06 17:20发布

问题:

I'm looking for a way to use the HBase Filter Language in PHP.

The HBase Book's chapter on Thrift seems formal and provides some filters for user to access HBase in PHP. A sample PHP code are also provided in this page, but I can not find any APIs in thrift (such as $client->scannerOpenWithFilterString(...)). I even checked the thrift definition file for HBase 0.92.0, but it has no interface for scannerOpenWithFilterString.

Versions used: Hadoop 0.20.203.0, Hbase 0.90.4 and thrift 0.8.0.

Does anyone know how to use PHP with filter features to access HBase?

回答1:

Hbase filters for Thrift API were implemented in v.0.92 There's a function named scannerOpenWithScan(), which takes 2 parameters - table name and TScan object.

You need to generate php classes for thrift using Hbase.thrift file, provided in hbase 0.92+ release

thrift -gen php Hbase.thrift 

In TScan object you can set startRow, stopRow, timestamp, columns, caching and filterString - which is exactly what you need.

Example: get rows 00100, 00200 and 00300

$flt = "RowFilter(=, 'regexstring:00[1-3]00')";
$scan = new TScan(array("filterString" => $flt));

or

$scan = new TScan();
$scan->setFilterString($flt);

and finally

$scanner = $client->scannerOpenWithScan("table_name", $scan);
while ($result = $client->scannerGet($scanner)) {
  ...
}

For information about filterString syntax and available filters see attachments here: https://issues.apache.org/jira/browse/HBASE-4176



标签: php hbase thrift