python 连接 impala
要想使用python连接hive,首先得下载以下几个包
pip3 install pure-sasl pip3 install thrift pip3 install thrift-sasl pip3 install cython pip3 install impyla
安装出错
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. Collecting impyla Using cached https://files.pythonhosted.org/packages/fb/e4/f2a71cb427cf5eb9d0dec0026220bbfe3efafe67b676e2b96ea5a5d3bff2/impyla-0.15.0.tar.gz ERROR: Complete output from command python setup.py egg_info: ERROR: The required version of setuptools (>=3.4.4) is not available, and can't be installed while this script is running. Please install a more recent version first, using 'easy_install -U setuptools'. (Currently using setuptools 0.9.8 (/usr/lib/python2.7/site-packages)) ---------------------------------------- ERROR: Command "python setup.py egg_info" failed with error code 2 in /tmp/pip-install-CH6vNu/impyla/
更新 setuptools
pip install --upgrade setuptools
下面进行测试,测试代码如下
from impala.dbapi import connect
conn = connect(host='192.168.0.10', port=21050)
cur = conn.cursor()
cur.execute('select name as num from user ;')
data_list=cur.fetchall()
for data in data_list:
print (data)如果报一下错误
Traceback (most recent call last):
File "updateImpala.py", line 65, in <module>
main(sys.argv[1:])
File "updateImpala.py", line 48, in main
cur = conn.cursor()
File "/Library/Python/2.7/site-packages/impala/hiveserver2.py", line 125, in cursor
session = self.service.open_session(user, configuration)
File "/Library/Python/2.7/site-packages/impala/hiveserver2.py", line 1016, in open_session
resp = self._rpc('OpenSession', req)
File "/Library/Python/2.7/site-packages/impala/hiveserver2.py", line 944, in _rpc
response = self._execute(func_name, request)
File "/Library/Python/2.7/site-packages/impala/hiveserver2.py", line 961, in _execute
return func(request)
File "/Library/Python/2.7/site-packages/impala/_thrift_gen/TCLIService/TCLIService.py", line 175, in OpenSession
self.send_OpenSession(req)
File "/Library/Python/2.7/site-packages/impala/_thrift_gen/TCLIService/TCLIService.py", line 182, in send_OpenSession
args.write(self._oprot)
File "/Library/Python/2.7/site-packages/impala/_thrift_gen/TCLIService/TCLIService.py", line 1250, in write
oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
TypeError: expecting list of size 2 for struct args使用thrift 0.9.3 版本
sudo pip install thrift==0.9.3
查看安装组件的版本
pip list
大数据
© 著作权归作者所有