新聞中心
python連接Hive的幾種方式

創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的貴港網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
·基于pyhive連接hive。
·基于impyla連接hive。
方法一:使用PyHive庫(kù)
安裝依賴包:其中sasl安裝可能會(huì)報(bào)錯(cuò),可以去https://www.lfd.uci.edu/~gohlke/pythonlibs/#sasl下載對(duì)應(yīng)版本安裝。
pip install sasl pip install thrift pip install thrift-sasl pip install PyHive
相關(guān)推薦:《Python基礎(chǔ)教程》
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)
# 下面是官網(wǎng)代碼:
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庫(kù)
impyla依賴包:
pip install six pip install bit-array pip install thriftpy
為了支持Hive還需要以下兩個(gè)包:
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 # 打印結(jié)果集的schema
results = cursor.fetchall() 分享名稱:創(chuàng)新互聯(lián)Python教程:python連接hive的包是什么
文章位置:http://www.5511xx.com/article/coogses.html


咨詢
建站咨詢
