from thrift.transport import TSocket
from hbase import Hbase
from hbase.ttypes import *
### create connection 创建连接
###
transport = TSocket.TSocket('127.0.0.1', 9090)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = Hbase.Client(protocol)
transport.open()
### diable and delete table 删除表
###
try:
client.disableTable('course')
client.deleteTable('course')
except IOError:
print('delete failed')
### create table 创建表
###
cf1 = ColumnDescriptor(name='stuInfo')
cf2 = ColumnDescriptor(name='Grades')
client.createTable('course', [cf1, cf2])
### list table 列出表
###
tables_list = client.getTableNames()
print((tables_list ))
### insert data 新增加数据
###
mutations = [Mutation(column="stuInfo:name", value = 'lili'),
Mutation(column="stuInfo:age", value = str(12)),
Mutation(column="stuIn
HBase python (thrift) API 示例
最新推荐文章于 2023-10-15 00:19:36 发布
本文介绍了如何通过Python的Thrift库与HBase进行数据操作。详细阐述了安装Thrift,配置HBase Thrift服务,以及Python中创建连接、插入数据、查询数据等基本操作步骤。
摘要由CSDN通过智能技术生成