最近正好解决了这个问题,先占坑,我周末来写详细的答案
下面是答案正文:
我们是基于pyhive这个包来连接python和hive。网上关于pyhive这个包的使用经验比较少,然后这个包也没有相关文档,所以当时我们就主要是基于源码和测试,打通了python和hive的连接:
首先是pyhive的安装:pyhive这个包依 赖于sasl,thrift,thrift-sasl这三个包,因此请参照下面的顺序安装,pip不行的时候,可以换用conda安装
pip install sasl
pip install thrift
pip install thrift-sasl
pip install PyHive
然后是网上的例子一般都是下面类似的demo:
import sys
from pyhive import hive
def dhive():
try:
conn = hive.connect(host="server_ip",port=10000, auth="...", database="...",username="...",password="...")
cursor = conn.cursor()
cursor.execute("select * from table_name")
res = cursor.fetchall()
conn.close()
for item in res:
print(item)
<