如何使用python3.4.5连接Hiveserver2

2024-05-16 05:02:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要从python3.4.5连接到Hiveserver2,代码正在hadoop集群上执行。通常,我从命令行执行hive -e "some query"。从其他服务器,我们使用提供IP和端口的仅用户名机制连接到Hiveserver2。但是,这不应该是必要的,因为我在同一个服务器上运行代码。在

我试过以下方法:

  1. Access Hive Data Using Python
  2. https://github.com/cloudera/impyla/issues/165
  3. How to connect to Hadoop Hive through python via pyhs2?
  4. https://pypi.python.org/pypi/impyla

但没有成功。我在连接阶段本身出错了。如果有人需要,我可以分享错误。在

如果没有别的,如果有人能详细说明 Hive client for Python 3.x


Tags: to代码命令行httpsip服务器pypihadoop
1条回答
网友
1楼 · 发布于 2024-05-16 05:02:28

从朋友的帮助和一点点调整在线可用的答案使用黑斑羚.dbapi解决了这个问题:

from impala.dbapi import connect
conn = connect(host='localhost', port = 10000,auth_mechanism='PLAIN')
cursor = conn.cursor()
cursor.execute('show databases')
results = cursor.fetchall()
print(type(results))
print(results)

相关问题 更多 >