HBase REST Filter ( SingleColumnValueFilter ) HBase REST Filter ( SingleColumnValueFilter ) hadoop hadoop

HBase REST Filter ( SingleColumnValueFilter )


Filter fields in the Scanner XML are strings formatted as JSON. Since the JSON for the filter has many quotes in it, I recommend using a separate file for curl's -d parameter, to avoid the single quote.

curl -v -H "Content-Type:text/xml" -d @args.txt http://hbasegw:8080/table/scanner

Where the file args.txt is:

<Scanner startRow="cm93MDE=" endRow="cm93MDg=" batch="1024">    <filter>    {        "latestVersion":true, "ifMissing":true,         "qualifier":"Y29sMQ==", "family":"ZmFtaWx5",         "op":"EQUAL", "type":"SingleColumnValueFilter",         "comparator":{"value":"MQ==","type":"BinaryComparator"}    }    </filter></Scanner>

How do you discover how the JSON filter string should look like? Here's an easy way through Java code that spits out the stringified filter given a standard Filter object from HBase's Java API.

SingleColumnValueFilter filter = new SingleColumnValueFilter(    Bytes.toBytes("family"),    Bytes.toBytes("col1"),    CompareFilter.CompareOp.EQUAL,    Bytes.toBytes("1"));System.out.println(ScannerModel.stringifyFilter(filter));

Notice that the JSON and the XML require data encoded in Base64. I've tested the above curl command on a table and it worked just fine.

In case you are wondering, yes, the REST API for scanners is not yet as developer-friendly as it can get.