python如何连接hive数据库

本文共有771个字,关键词:

问题:python如何连接hive数据仓库?

解决:使用pyhive

方法:

1、安装三个python包,网上有的说要安装sasl,但我没安装成功,然后发现不安装也可以

pip install thrift==0.20.0 thrift-sasl==0.4.3 pyhive==0.7.0

2、建立连接

from pyhive import hive
from .config import config

hive_conn = hive.Connection(
    host=config['HV_SVR'],
    port=10000,
    auth="CUSTOM",
    database=config['HV_DB'],
    username=config['HV_USER'],
    password=config['HV_PASS']
)
hive_cur = hive_conn.cursor()
hive_cur.execute('select * from table limit 10')
for result in hive_cur.fetchall():
    print(result)

# 关闭连接
cursor.close()
conn.close()

参考:

https://www.cnblogs.com/hider/p/16279747.html
版权声明:本文为作者原创,如需转载须联系作者本人同意,未经作者本人同意不得擅自转载。
添加新评论
暂无评论