`
jack_boy
  • 浏览: 139751 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

happybase访问Hbase

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

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

happybase使用很简单,与hbase shell 用法类似
主要的用法都很简单,在其官方网站happybase上都有。
这里主要记录一个错误。
  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


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

引用
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"



参考:
http://hbase.apache.org/book/thrift.html#example-filter-strings
https://github.com/wbolster/happybase/blob/master/tests/test_api.py
0
5
分享到:
评论

相关推荐

    Python访问Hbase的库文件

    标题:"Python访问Hbase的库文件:Hbase.py与ttypes.py的替代解决方案" 在大数据处理的世界里,Apache HBase是一种分布式的、面向列的NoSQL数据库系统,特别适合于存储大量半结构化数据。HBase的分布式特性使其在...

    hbase启动说明和python脚本

    `happybase`是一个基于`thriftpy`的HBase Python客户端,提供了简单易用的API。使用`happybase`,我们可以创建连接、创建表、插入数据、查询数据等。 例如,一个简单的`conn_happy.py`脚本可能包含以下内容: ```...

    Python连接Hbase

    HBase是Apache Hadoop生态系统中的一个分布式、面向列的数据库,它提供实时访问大数据的能力。它支持海量数据存储,同时提供了快速随机读取性能,非常适合处理半结构化的数据。 Python连接HBase的过程主要分为以下...

    thrift2 查询hbase

    在使用Python访问HBase之前,我们需要安装必要的Python库。主要的依赖库包括`happybase`,它是Python的HBase Thrift客户端。你可以使用pip进行安装: ``` pip install happybase ``` 2. **连接HBase** 连接...

    Python-提供Hbase自动化部署方案WhaleAI专注人工智能大数据

    7. **安全与权限**:如果需要,可以配置HBase的安全机制,如Kerberos,以确保数据访问的安全性。 通过WhaleAI的自动化部署方案,开发者可以更专注于人工智能和大数据应用的开发,而不是花费大量时间在基础架构的...

    python连接hbase的lib(版本0.98.8)

    HBase是一个分布式的、面向列的NoSQL数据库,它构建在Hadoop之上,提供实时访问大规模数据集的能力。然而,由于HBase主要是为Java设计的,非Java语言如Python需要通过特定的接口来实现连接,这就是Thrift接口的作用...

    hbase-elasticsearch:从 hbase 创建弹性搜索索引的脚本

    **HBase**:Apache HBase是一个开源的、分布式的、版本化的NoSQL数据库,它建在Hadoop文件系统(HDFS)之上,提供高吞吐量的数据访问。HBase适合于存储非结构化或半结构化的松散数据,例如日志和时间序列数据。 **...

    HotColdData:使用 PostgreSQL 和 HBase 进行冷热数据存储

    Python提供了诸如`psycopg2`库用于与PostgreSQL交互,`happybase`库则用于连接和操作HBase。这些库可以帮助开发人员方便地构建数据管道,将数据从PostgreSQL的热存储迁移到HBase的冷存储,或者根据业务需求进行数据...

Global site tag (gtag.js) - Google Analytics