使用HBase REST API进行过滤 [英] Filter using HBase REST API
问题描述
curl -X GET'http:// server:9090 / test / Row-1 / Action:ActionType /'-h 'Accept:application / json'
这会返回Row-1中的Action:ActionType列。如果我想使用GET命令执行WHERE子句的等价操作,我会卡住。我不确定它甚至可能吗?例如,如果我想查找Action:ActionType = 1的所有记录。
帮助表示赞赏!
您可以通过使用过滤器(这里是首先,创建一个XML文件(
myscanner.xml $ c $>),然后在CURL请求中创建一个名为SingleColumnValueFilter
描述你的扫描。这里我们要根据限定符值进行过滤,使用 EQUAL
运算符):
< Scanner batch =10>
< filter>
{
type:SingleColumnValueFilter,
op:EQUAL,
family:< FAMILY_BASE64>,
qualifier :< QUALIFIER_BASE64>,
latestVersion:true,
comparator:{
type:BinaryComparator,
value:< ; SEARCHED_VALUE_BASE64>中
}
}
< / filter>
< / Scanner>
您应该替换< FAMILY_BASE64>
, < QUALIFIER_BASE64>
和< SEARCHED_VALUE_BASE64>
用您自己的值(值必须转换为base64,您可以执行然后,使用这个提交一个CURL请求到HBase REST API,然后将这个请求提交给HBase REST API。 echo -en $ {FAMILY} | base64
。
curl -vi -X PUT \
-HContent-Type:text / xml\
-d @ myscanner.xml \
http:// $ {HOST}:$ {REST_API_PORT} / $ {TABLE_NAME} / scanner /
这个请求应该返回一个Scanner对象,如:
[...]
然后使用给定的扫描器遍历结果(请求多次迭代):
位置:http:// $ {HOST}:$ {REST_API_PORT} / $ {TABLE_NAME} / scanner / 149123344543470bea57a
<$ p $ b$ p>
curl -vi -X GET \
-HAccept:text / xml\
http:// $ {HOST}:$ {REST_API_PORT} / $ {TABLE_NAME} / scanner / 149123344543470bea57a
您也可以接受application / json
而不是XML。请注意,结果是以base64编码的。
来源:
$ b
HBase REST Filter(SingleColumnValueFilter)
列表您可以使用的过滤器: https://gist.github.com/stelcheck/3979381
有关HBase REST API的Cloudera文档: https://www.cloudera.com/documentation/enterprise/5-9-x/topics/admin_hbase_rest_api.html
Does anyone know anything about the HBase REST API? Im currently writing a program which inserts and reads from HBase using curl commands. When trying to read I use the curl get command, e.g.
curl -X GET 'http://server:9090/test/Row-1/Action:ActionType/' -h 'Accept:application/json'
This returns the column Action:ActionType from Row-1. If I want to do the equivalent of a WHERE clause using the GET command I am stuck however. Im not sure its even possible? If I want to find all records where Action:ActionType =1 for example. Help is appreciated!
You can do this by using a filter (here a SingleColumnValueFilter
) in your CURL request.
First, create a XML file (myscanner.xml
) describing your scan. Here we want to filter according to a qualifier value, with EQUAL
operator) :
<Scanner batch="10">
<filter>
{
"type": "SingleColumnValueFilter",
"op": "EQUAL",
"family": "<FAMILY_BASE64>",
"qualifier": "<QUALIFIER_BASE64>",
"latestVersion": true,
"comparator": {
"type": "BinaryComparator",
"value": "<SEARCHED_VALUE_BASE64>"
}
}
</filter>
</Scanner>
You should replace <FAMILY_BASE64>
, <QUALIFIER_BASE64>
and <SEARCHED_VALUE_BASE64>
with your own values (values must be converted to base64, you can do echo -en ${FAMILY} | base64
.
Then, submit a CURL request to HBase REST API with this XML file as data :
curl -vi -X PUT \
-H "Content-Type:text/xml" \
-d @myscanner.xml \
"http://${HOST}:${REST_API_PORT}/${TABLE_NAME}/scanner/"
This request should return a Scanner object, like :
[...]
Location: http://${HOST}:${REST_API_PORT}/${TABLE_NAME}/scanner/149123344543470bea57a
Then use the given scanner to iterate through results (request multiple times to iterate) :
curl -vi -X GET \
-H "Accept: text/xml" \
"http://${HOST}:${REST_API_PORT}/${TABLE_NAME}/scanner/149123344543470bea57a"
You can also accept "application/json"
instead of XML. Notice that the results are base64 encoded.
Sources :
HBase REST Filter ( SingleColumnValueFilter )
A list of filters you can use : https://gist.github.com/stelcheck/3979381
Cloudera documentation about HBase REST API : https://www.cloudera.com/documentation/enterprise/5-9-x/topics/admin_hbase_rest_api.html
这篇关于使用HBase REST API进行过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!