Python使用happybase操作Hbase
1. 需开启thrift服务, hbase thrift start
2. happybase连接 Hbase, 读写, delete, 多线程建表
3. 对读取效率做简单测试
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File : test_happybase.py
# @Author: Wade Cheung
# @Date : 2019/1/1
# @Desc : happybase连接 Hbase, 读写, delete, 多线程建表.
import threading
import time
import happybase
def read_hbase():
connection = happybase.Connection(host='192.168.1.107', port=9090)
table = connection.table('test')
# row_key = '1' # 根据key读value
# info = table.row(row_key)
# print('输出: ', info, '\n')
dic = {} # 存放到字典里
for key, value in table.scan():
dic[key.decode()] = dict(map(lambda x: (x[0].decode(), x[1].decode()), value.items()))
print(len(dic)