python如何連接hive

這篇文章將為大家詳細(xì)講解有關(guān)python 如何連接hive,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

成都創(chuàng)新互聯(lián)公司主要業(yè)務(wù)有網(wǎng)站營銷策劃、網(wǎng)站設(shè)計制作、網(wǎng)站制作、微信公眾號開發(fā)、小程序開發(fā)HTML5建站、程序開發(fā)等業(yè)務(wù)。一次合作終身朋友,是我們奉行的宗旨;我們不僅僅把客戶當(dāng)客戶,還把客戶視為我們的合作伙伴,在開展業(yè)務(wù)的過程中,公司還積累了豐富的行業(yè)經(jīng)驗(yàn)、全網(wǎng)營銷推廣資源和合作伙伴關(guān)系資源,并逐漸建立起規(guī)范的客戶服務(wù)和保障體系。 

python連接hive的幾種方式

·基于pyhive連接hive。

·基于impyla連接hive。

方法一:使用PyHive庫

安裝依賴包:其中sasl安裝可能會報錯,可以去https://www.lfd.uci.edu/~gohlke/pythonlibs/#sasl下載對應(yīng)版本安裝。

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)
  
# 下面是官網(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庫

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   # 打印結(jié)果集的schema 
results = cursor.fetchall()

關(guān)于python 如何連接hive就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

本文標(biāo)題:python如何連接hive
網(wǎng)頁地址:http://muchs.cn/article26/pdgjcg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站、Google、靜態(tài)網(wǎng)站、網(wǎng)頁設(shè)計公司、服務(wù)器托管、云服務(wù)器

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)