HBase REST Filter ( SingleColumnValueFilter )

后端 未结 1 1106
无人共我
无人共我 2020-12-29 03:15

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

相关标签:
1条回答
  • 2020-12-29 04:00

    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.

    0 讨论(0)
提交回复
热议问题