由于win系统上无法正常使用PyHive访问Hive,所以改用impyla访问。
参考:走马兰台
环境:
python 3.7.3,Win10
安装依赖:
six-1.13.0
bit-array-0.1.0
pure-sasl 0.6.2
thrift-sasl-0.2.1
thrift 0.9.3
thriftpy-0.3.9
impyla-0.16.2
修改部分源码:
报错:TypeError: can't concat str to bytes
需要在文件 ".\Python37\lib\site-packages\thrift_sasl\__init__.py
"第94行代码
def _send_message(self, status, body):
header = struct.pack(">BI", status, len(body))
self._trans.write(header + body)
self._trans.flush()
改为
def _send_message(self, status, body):
header = struct.pack(">BI", status, len(body))
if(type(body) is str):
body = body.encode()
self._trans.write(header + body)
self._trans.flush()
测试:
from impala.dbapi import connect
conn = connect(host='test.com', port=10000, auth_mechanism='PLAIN', user='admin', password='pwd', database='db_test')
cur=conn.cursor()
cur.execute('SHOW TABLES')
cur.fetchall()
保存,用jupyter写代码的记得要restart kernel。