导语:
本文主要介绍了关于python 连接hive的包是什么的相关知识,希望可以帮到处于编程学习途中的小伙伴
python连接hive的几种方式
·
基于pyhive连接hive。
·
基于impyla连接hive。
方法一:使用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及其依赖包的源码
Python脚本代码:
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()
本文为原创文章,版权归知行编程网所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ 如何使用python位置参数12/20
- ♥ 菜鸟玩Python|笑看新倚天屠龙记03/27
- ♥ anaconda和python有什么关系09/21
- ♥ 如何快速为python代码添加注释09/14
- ♥ 如何在 Python 中编写复数10/05
- ♥ 熬夜到虚脱整理出来的Python的正则表达式总结02/09
内容反馈