Python连接Hive(基于PyHive)

遇见的坑

1.连hive之前安装pyhs2,结果发现要sasl,发现sasl还不能安装,需要到

https://www.lfd.uci.edu/~gohlke/pythonlibs/#sasl 这里下载对应的包,我的得python3.7-win7

安装好sasl之后,紧接着安装pysh2是可以了。

https://blog.csdn.net/a6822342/article/details/80713652

#第三个版本还是有点问题
# 'TSocket' object has no attribute 'isOpen'修改了thrift-sasl的版本,降到0.2.1,结果还是有点问题
from impala.dbapi import connect
from impala.util import as_pandas
#conn = hive.Connection(host='192.168.247.50',port=10000,username='jtsk',password='dah8\293A',database='jt_sk_ods')#host主机ip,port:端口号,username:用户名,database:使用的数据库名称

#sql = "SELECT report_date,sum(use_count) as use_count,sum(total_amount) as total_amount from jt_sk_ods.device_report GROUP BY report_date limit 10"

conn = connect(host='192.168.247.50', port=10000, auth_mechanism='PLAIN', user='jtsk', password='dah8\293A', database='jt_sk_ods')
cursor = conn.cursor()
sql = "SELECT report_date,sum(use_count) as use_count,sum(total_amount) as total_amount from jt_sk_ods.device_report GROUP BY report_date limit 10"
cursor.execute(sql)
print(as_pandas(cursor))

猜你喜欢

转载自blog.csdn.net/OYY_90/article/details/89325765