happybase访问Hbase

Java以为的语言访问Hbase都是通过thrift进行访问的,因此需要在Hbase上开启thrift服务
如果用
hbase-deamon.sh start

启动服务,默认用的是thrift2,在用happybase的时候会出现版本不兼容的问题,因此用thrift来启动
hbase thrift -p 9090 start

happybase使用很简单,与hbase shell 用法类似
主要的用法都很简单,在其官方网站[url="http://happybase.readthedocs.org/en/latest/user.html"]happybase[/url]上都有。
这里主要记录一个错误。
  File "test.py", line 21, in <module>
for k, d in g:
File "/home/jack_boy/product/lib/python2.6/site-packages/happybase/table.py", line 374, in scan
self.name, scan, {})
File "/home/jack_boy/product/lib/python2.6/site-packages/happybase/hbase/Hbase.py", line 1919, in scannerOpenWithScan
return self.recv_scannerOpenWithScan()
File "/home/jack_boy/product/lib/python2.6/site-packages/happybase/hbase/Hbase.py", line 1937, in recv_scannerOpenWithScan
raise x
thrift.Thrift.TApplicationException: Internal error processing scannerOpenWithScan


源代码:
import happybase
import sys

#reload(sys)
#sys.setdefaultencoding('utf-8')

connection = happybase.Connection('192.168.1.110')

#connection.open()
#print connection.tables()
table = connection.table('testTable')


g = table.scan(filter="SingleColumnValueFilter('f', 'id', =, '852223')", limit=10)
for k, d in g:
print k, d


改为:
[color=blue]g = table.scan(filter="SingleColumnValueFilter('f', 'id', =, 'substring:852223')", limit=10)[/color]
程序正确运行,输出结果

[quote]The general syntax of a comparator is: ComparatorType:ComparatorValue

The ComparatorType for the various comparators is as follows:

BinaryComparator - binary

BinaryPrefixComparator - binaryprefix

RegexStringComparator - regexstring

SubStringComparator - substring

The ComparatorValue can be any value.

Example 12.3. Example 1

>, 'binary:abc' will match everything that is lexicographically greater than "abc"


Example 12.4. Example 2

=, 'binaryprefix:abc' will match everything whose first 3 characters are lexicographically equal to "abc"


Example 12.5. Example 3

!=, 'regexstring:ab*yz' will match everything that doesn't begin with "ab" and ends with "yz"


Example 12.6. Example 4

=, 'substring:abc123' will match everything that begins with the substring "abc123"
[/quote]


参考:
http://hbase.apache.org/book/thrift.html#example-filter-strings
https://github.com/wbolster/happybase/blob/master/tests/test_api.py
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值