2017-07-06 40 views
0

我需要從Python 3.4.5連接到Hiveserver2,並且代碼正在hadoop集羣本身上執行。通常,我從命令行執行hive -e "some query"。從其他服務器,我們使用僅提供用戶名的機制連接到Hiveserver2,提供IP和端口。然而,這不應該是必要的,因爲我在這裏運行在同一臺服務器上的代碼。如何使用Python連接Hiveserver2 3.4.5

我曾嘗試以下:

  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

,但沒有成功。我在連接階段本身出現錯誤。如果有人需要,我可以分享錯誤。

如果不出意外,這將是巨大的,如果有人能在答案闡述從朋友和使用impala.dbapi網上提供的答案有點扭捏 Hive client for Python 3.x

+0

包含演示問題和錯誤/跟蹤的最小代碼示例會很有用。 –

回答

0

幫助解決該問題:

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)