Python 官方文档:入门教程 => 点击学习
方法一:使用PyHive库 安装依赖包:其中sasl安装可能会报错,可以去https://www.lfd.uci.edu/~Gohlke/pythonlibs/#sasl下载对应版本安装。 pip install sasl pip in
方法一:使用PyHive库
安装依赖包:其中sasl安装可能会报错,可以去https://www.lfd.uci.edu/~Gohlke/pythonlibs/#sasl下载对应版本安装。
pip install sasl
pip install thrift
pip install thrift-sasl
pip install PyHive
Python脚本代码操作:
from pyhive import hive # or import hive
conn = hive.Connection(host='****', port=****, username='****', database='****')
cursor.execute(''SELECT * FROM my_awesome_data LIMIT 10'')
for i in range(****):
sql = "INSERT INTO **** VALUES ({},'username{}')".fORMat(value, str(username))
cursor.execute(sql)
# 下面是官网代码:
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())
方法二:使用 impyla库
impyla依赖包:
pip install six
pip install bit_array
pip install thriftpy
为了支持Hive还需要以下两个包:
pip install sasl
pip install thrift_sasl
可在Python PyPI中下载impyla及其依赖包的源码
from impala.dbapi import connect
conn = connect(host ='****',port = ****)
cursor = conn.cursor()
cursor.execute('SELECT * FROM mytable LIMIT 100')
print cursor.description # 打印结果集的schema
results = cursor.fetchall()
--结束END--
本文标题: Python操作Hive的两种方法总结
本文链接: https://www.lsjlt.com/news/191656.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0