由於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。