xmlresthadoophbasestargate

HBase REST Filter ( SingleColumnValueFilter )


I cannot figure out how to use filters in the HBase REST interface (HBase 0.90.4-cdh3u3). The documentation just gives me a schema definition for a "string", but doesn't show how to use it.

So, I'm able to do this:

curl -v -H 'Content-Type: text/xml' -d '<Scanner startRow="ddo" stopRow="ddp" batch="1024"/>' 'http://hbasegw:8080/table/scanner'

and then retrieve with

curl -s -H "Content-Type: text/xml" http://hbasegw:8080/table/scanner/13293426893883128482b | tidy -i -q -xml

But now I want to use a SingleColumnValueFilter and have to encode that somehow in the XML. Does anyone have an example for this?

Thanks, Mario


Solution

  • 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.