0

我使用 impyla 和 ibis 连接 hive 服务器,但我得到了错误。我尝试了以下代码:

from impala.dbapi import connect
impcur = connect(host="kudu3", port=10000, database="yingda_test", password=None, user='admin', kerberos_service_name='None').cursor()

新的错误出来了:

Traceback (most recent call last):
  File "/Users/edy/src/PythonProjects/dt-center-algorithm/test/1.py", line 4, in <module>
    impcur = connect(host="kudu3", port=10000, database="yingda_test", password=None, user='admin', kerberos_service_name='None').cursor()
  File "/usr/local/conda3/envs/py37/lib/python3.7/site-packages/impala/hiveserver2.py", line 129, in cursor
    session = self.service.open_session(user, configuration)
  File "/usr/local/conda3/envs/py37/lib/python3.7/site-packages/impala/hiveserver2.py", line 1187, in open_session
    resp = self._rpc('OpenSession', req, True)
  File "/usr/local/conda3/envs/py37/lib/python3.7/site-packages/impala/hiveserver2.py", line 1080, in _rpc
    response = self._execute(func_name, request, retry_on_http_error)
  File "/usr/local/conda3/envs/py37/lib/python3.7/site-packages/impala/hiveserver2.py", line 1142, in _execute
    .format(self.retries))
impala.error.HiveServer2Error: Failed after retrying 3 times

thrift 0.15.0 thrift-sasl 0.4.3 thriftpy2 0.4.14 pure-sasl 0.6.2 sasl 0.2.1 thrift-sasl 0.4.3 ibis-framework 2.0.0 impyla 0.17.0 python 版本:3.7.12 with anaconda

而且我试过ibis-1.3.0和2.0版本。你们可以给一些建议吗?很多

4

1 回答 1

0

我也遇到了这个问题。

我的代码是:

from impala.dbapi import connect
import psycopg2

conn_hive = connect(host="xxx.xxx.xxx.xxx", port=xxx, user='admin', 
                    password='password', database='xxx', auth_mechanism="PLAIN", timeout=6000)
hive_cursor = conn_hive.cursor()
hive_cursor.execute(query_sql)
data_list = hive_cursor.fetchall()
...get data...
hive_cursor.close()
conn_hive.close()

经过我和同事的尝试,我们发现手动重新连接hive就可以成功。

这意味着如果您想从同一个 hive 数据库中获取不同的数据,您最好关闭连接并通过以下代码手动重新连接 hive:

conn_hive = connect(host="xxx.xxx.xxx.xxx", port=xxx, user='admin', 
                    password='password', database='xxx', auth_mechanism="PLAIN", timeout=6000)
hive_cursor = conn_hive.cursor()
hive_cursor.execute(query_sql)
data_list = hive_cursor.fetchall()
...get data1...
hive_cursor.close()
conn_hive.close()

conn_hive = connect(host="xxx.xxx.xxx.xxx", port=xxx, user='admin', 
                    password='password', database='xxx', auth_mechanism="PLAIN", timeout=6000)
hive_cursor = conn_hive.cursor()
hive_cursor.execute(query_sql)
data_list = hive_cursor.fetchall()
...get data2...
hive_cursor.close()
conn_hive.close()

最后同事告诉我,最近黑斑羚出现了问题。

于 2021-11-07T15:22:29.543 回答