python如何连接hive-创新互联
创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!

这篇文章将为大家详细讲解有关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 如何连接hive就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
本文名称:python如何连接hive-创新互联
当前网址:http://www.pengzhouwz.cn/article/dhdchp.html
其他资讯
- 如何玩转短视频营销看这里,如何利用短视频进行营销
- 网址域名多少钱,com域名多少钱一年
- MicrosoftXMLCoreServices整数截断漏洞加固
- php查看数组数据一样 php查看数据类型
- 如何使用阿里云上的mysql数据库服务器 阿里云 mysql
- 免费国外邮件服务器,快来享受海外信箱服务!(国外免费邮件服务器)
- 深入理解JavaScriptErrors和StackTraces
- 新闻客户端数据库表:优化内存消耗,提升加载速度(新闻客户端数据库表)
- 自带掌阅电子书无法识别TXT?(windows打不开txt文件怎么打开)
- 体验优势Linux系统:体验优势究竟何在?(linux系统有那些)


咨询
建站咨询
