欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

python连接hive--Pyhive

发布时间:2023/12/31 python 52 豆豆
生活随笔 收集整理的这篇文章主要介绍了 python连接hive--Pyhive 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

Pyhive

安装包

pip install sasl pip install thrift pip install thrift-sasl pip install PyHive # 安装对应的包 sasl可能会报错 #下载sasl文件

sasl下载

执行语句

第一种

from pyhive import hive def select_pyhive(sql):# 创建hive连接conn = hive.Connection(host='##', port=##, username='##', database='库名')cur = conn.cursor()try:# c = cur.fetchall()df = pd.read_sql(sql, conn)return dffinally:if conn:conn.close() sql='select * from table limit 10' df = select_pyhive(sql)

第二种

from sqlalchemy.engine import create_engine def _sql_hive():engine = create_engine('aaaaa://host:port/hive/')df = pd.read_sql("""select * from table limit 100""", engine)return df df = _sql_hive()

总结

以上是生活随笔为你收集整理的python连接hive--Pyhive的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。