Hbase连接使用
pip install happybase
pip install thrift
import happybase
# 1.从数据库导入到hbase
if __name__ != '__main__':
import pandas as pd
from sqlalchemy import create_engine
conn = happybase.Connection("192.168.160.100", 9090)
engine = create_engine('mysql+pymysql://root:123456@192.168.130.77:3306/paixin', echo=True)
sql = "SELECT * FROM paixin WHERE id >= 4000"
data = pd.read_sql(sql, engine)
print(conn.tables())
paixin = conn.table("paixin")
for item in data.values:
# colfam列名
d = {"colfam:img_id": item[1], "colfam:img_url": item[2], "colfam:store_path": item[3]}
print(d)
id_ = str(item[0])
paixin.put(id_, d)
pass
# 2.基本操作
if __name__ == '__main__':
import time
conn = happybase.Connection("192.168.160.100", 9090)
paixin = conn.table('paixin') # 指定表
row = paixin.row("3567") # 通过指定列簇来检索数据
print(row)
rows = paixin.rows(['4568', '4456'])
print(rows)
print(paixin)
s = time.time()
for k, v in paixin.scan():
print(k, v)
pass
e = time.time()
print(e-s)
pass