Java以为的语言访问Hbase都是通过thrift进行访问的,因此需要在Hbase上开启thrift服务
如果用
启动服务,默认用的是thrift2,在用happybase的时候会出现版本不兼容的问题,因此用thrift来启动
happybase使用很简单,与hbase shell 用法类似
主要的用法都很简单,在其官方网站[url="http://happybase.readthedocs.org/en/latest/user.html"]happybase[/url]上都有。
这里主要记录一个错误。
源代码:
改为:
[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
如果用
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