python操作Hbase
文章目录python操作Hbase1.需要安装thriftThrift是什么?能做什么?下载thrift操作Hbase在Hbase中开启thrift服务python操作Hbasepython操作Hbase1.需要安装thriftThrift是什么?能做什么?Thrift是Facebook于2007年开发的跨语言的rpc服框架,提供多语言的编译功能,并提供多种服务器工作模式;用户通过Thrift的I
·
python操作Hbase
1.需要安装thrift
Thrift是什么?能做什么?
Thrift是Facebook于2007年开发的跨语言的rpc服框架,提供多语言的编译功能,
并提供多种服务器工作模式;用户通过Thrift的IDL(接口定义语言)来描述接口函数及数据类型,
然后通过Thrift的编译环境生成各种语言类型的接口文件,用户可以根据自己的需要采用不同的语言开发客户端代码和服务器端代码。
下载thrift
先下载thrift,如下,选择0.10.0版本
http://mirrors.hust.edu.cn/apache/thrift
Thrift 下载和安装教程
win10就是将存放Thrift.exe文件的路径写入环境变量,(将Thrift0.10.0.exe,改为Thrift.exe)
在cmd终端,输入 thrift -version,如果输出版本号,就说名成功安装,
注意:Thrift.exe 文件不需要双击安装,直接将路径存入环境变量就行
(双击Thrift.exe 文件,会闪退,这个问题不用管)
操作Hbase
在Hbase中开启thrift服务
# 进入hbase的bin目录
cd /usr/local/hbase/bin
# 执行以下命令
hbase-daemon.sh start thrift
然后使用jps命令,查看进程
99200 HQuorumPeer
3842 ResourceManager
99298 HMaster
3475 DataNode
4774 HRegionServer
3673 SecondaryNameNode
5337 Jps
3370 NameNode
3947 NodeManager
5262 ThriftServer
有ThriftServer这个进程表示成功开启
python操作Hbase
import happybase
#链接,端口默认是9090 hbase thrift 启动的默认端口也是9090
connection = happybase.Connection('192.168.126.131',port=9090)
# connection.tables():获取Hbase实例中的表名列表,返回一个list
table_name_list = connection.tables()
print(table_name_list)
输出:
[b'tbl_stu', b'tbl_user']
import happybase
#链接,端口默认是9090 hbase thrift 启动的默认端口也是9090
connection = happybase.Connection('192.168.126.131',port=9090)
# connection.tables():获取Hbase实例中的表名列表,返回一个list
table_name_list = connection.tables()
print(table_name_list)
# 输出:[b'qian_cheng_wu_you', b'student', b'tbl_stu', b'tbl_user']
# connection.table(name,user_prefix=True):获取一个表对象,返回一个
table = connection.table('qian_cheng_wu_you')
print(table)
# table.put(rowkey, {"info:content": value})
content = table.put("1004",{'info:name':"111111"})
print(content)
table.put("1005",{'info:age':"65"})
row = table.row("1005")
print(row)
# {b'info:age': b'65', b'info:name': b'5555555'}
row = table.rows(["1004","1005"])
print(row)
for key, value in table.scan():
#print(key,value)
data = str(value).encode().decode('unicode-escape').encode('raw_unicode_escape').decode()
print (key, str(data))
乱码问题
【HBase数据开发】解决Python类库Happyhbase读取数据中文乱码问题
data = str(value).encode().decode('unicode-escape').encode('raw_unicode_escape').decode()
print (key, str(data))
更多推荐
已为社区贡献1条内容
所有评论(0)