使用python操作HBase
来源:互联网 发布:淘宝鲜花速递 编辑:程序博客网 时间:2024/05/29 14:01
最近要使用spark操作HBase, scala还是不熟悉,想了下还是学习下用python怎么操作HBase。
网上资料蛮多的,现在实现了python访问hbase,下一步要把它应用到spark上。
1. 下载thrift包
thrift 我的理解是它提供一个服务,通过它其他的编程语言也能够访问到hbase数据库。
我的虚拟机无法上网,安装还是挺头疼的事。先是在mac 下先brew install thrift, 安装成功后测试:thrift -version
2. 生成对应的python文件。
使用的是hbase 1.0.0, 去官网下载了hbase 1.0.0的源代码。找到hbase-1.0.0/hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift 下的文件 Hbase.thrift
用它来生成对应的python文件。其中有两个文件夹一个thrift, 一个 thrift2。 2 是之前的版本的优化,这个以后再研究。
使用命令
thrift --gen py HBase.thrift 会在当前目录下生成文件:
如果是linux系统, 需要下载thrit源代码, 然后分别使用命令:
./configure
make
make install
过程中可能需要安装依赖包,应该是自动下载的吧不是很清楚。
3. 启动hbase的thrift服务
启动hbase后,使用命令:
其中,还需要安装下python下的thrift模块。下载好的thrift源代码后,执行一下目录下的setup.py文件进行安装, 使用命令 sudo python setup.py install
5. 下面可以使用python代码测试连接了
>>> import sys
>>> sys.path.append('/home/hadoop/Documents/thrift/gen-py/hbase') # 引入正确的生成文件gen-py路径
>>> import Hbase
>>> import ttypes
>>> from thrift.transport import TSocket
>>> from thrift.protocol import TBinaryProtocol
>>> transport = TSocket.TSocket('localhost',9090)
>>> protocol = TBinaryProtocol.TBinaryProtocol(transport)
>>> client = Hbase.Client(protocol)
>>> transport.open()
>>> client.getTableNames()
['T_OS_P', 'T_PO_S', 'T_SO_P_1', 'T_SP_O', 'member1', 'member2', 'scores', 'test', 'test_python_hbase', 'users', 'wordcount', 'wordcount2', 'wordcount3']
>>>
- 使用python操作HBase
- python操作 hbase 数据
- Python操作HBase
- Hbase Python 操作准备
- python访问、操作hbase
- Python操作HBase
- 使用Python语言通过Thrift 网关操作HBase
- 使用Jython操作HBase
- 使用java操作HBase
- 使用mapreduce操作Hbase
- 使用python访问hbase
- python通过thrift操作hbase
- HappyBase安装&Python操作HBase
- python操作hbase 远程连接
- HBase.使用shell脚本进行HBase操作
- 使用 Java API 操作 HBase
- 使用scala操作hbase api
- 【Hadoop】使用MapReduce操作HBase
- 为什么在Spring的配置里,最好不要配置xsd文件的版本号
- php post example
- Web Service基础
- 小的知识点
- web开发中常用的路劲问题总结
- 使用python操作HBase
- Linux最大线程数限制及当前线程数查询
- CURL使用SSL证书访问HTTPS
- 并发学习笔记(三):join与wait/notify
- 39.Oracle深度学习笔记——自动创建ASM UDEV设备脚本
- 学习前端开发
- artdialog弹窗插件
- 是否要用Hadoop
- [POJ 3083]Children of the Candy Corn[DFS+BFS]