HBase REST Filter ( SingleColumnValueFilter )

元气小坏坏 提交于 2019-11-29 02:07:57

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/9302097/hbase-rest-filter-singlecolumnvaluefilter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!