HBase REST过滤器(SingleColumnValueFilter) [英] HBase REST Filter ( SingleColumnValueFilter )
问题描述
我无法弄清楚如何在HBase REST界面中使用过滤器(HBase 0.90.4-cdh3u3)。文档只是给了我一个字符串的模式定义,但没有说明如何使用它。
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.
所以,我可以这样做:
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
但是现在我想使用SingleColumnValueFilter并且必须以某种方式进行编码在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
推荐答案
扫描器XML中的过滤器字段是格式化为JSON的字符串。由于过滤器的JSON中包含许多引号,因此建议使用单独的文件来卷曲-d参数,以避免单引号。
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 -HContent-Type:text / xml-d @ args.txt http :// hbasegw:8080 / table / scanner
文件 args.txt
是:
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>
您如何发现JSON过滤器字符串的外观?一种简单的方法,通过Java代码,从HBase的Java API给出一个标准的Filter对象,将字符串化的过滤器分离出来。
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));
请注意,JSON和XML需要使用Base64编码的数据。我已经在桌上测试了上面的curl命令,它工作得很好。
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.
如果您想知道,是的,扫描仪的REST API尚不像开发人员友好,因为它可以得到。
In case you are wondering, yes, the REST API for scanners is not yet as developer-friendly as it can get.
这篇关于HBase REST过滤器(SingleColumnValueFilter)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!