基于PyHive库使用python访问Hive
安装:去sasl下载地址下载所需sasl,要和python版本匹配,pip install sasl‑xxx.whl (如果没安装wheel,pip install wheel)conda install pyhive使用:同步from pyhive import presto# or import hivecursor = presto.connect('localho...
·
安装:
- 去sasl下载地址下载所需sasl,要和python版本匹配,pip install sasl‑xxx.whl (如果没安装wheel,pip install wheel)
- conda install pyhive
使用:
同步
from pyhive import presto # or import hive
cursor = presto.connect('localhost').cursor()
cursor.execute('SELECT * FROM my_awesome_data LIMIT 10')
print cursor.fetchone()
print cursor.fetchall()
异步
from pyhive import hive
from TCLIService.ttypes import TOperationState
cursor = hive.connect('localhost').cursor()
cursor.execute('SELECT * FROM my_awesome_data LIMIT 10', async=True)
status = cursor.poll().operationState
while status in (TOperationState.INITIALIZED_STATE, TOperationState.RUNNING_STATE):
logs = cursor.fetch_logs()
for message in logs:
print message
# If needed, an asynchronous query can be cancelled at any time with:
# cursor.cancel()
status = cursor.poll().operationState
print cursor.fetchall()
更多推荐
已为社区贡献1条内容
所有评论(0)