如何使用Python 3.4.5连接Hiveserver2

时间:2017-07-06 06:35:01

标签: python python-3.x hadoop hive python-3.4

我需要从Python 3.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
  5. 但没有成功。我在连接阶段本身遇到错误。如果有人要求,我可以分享错误。

    如果没有别的,如果有人可以详细说明答案,那就太好了 Hive client for Python 3.x

1 个答案:

答案 0 :(得分:1)

来自朋友的帮助,使用impala.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)
相关问题