創(chuàng)新互聯(lián)www.cdcxhl.cn八線動(dòng)態(tài)BGP香港云服務(wù)器提供商,新人活動(dòng)買多久送多久,劃算不套路!
這篇文章將為大家詳細(xì)講解有關(guān)python 如何連接hive,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
python連接hive的幾種方式
·基于pyhive連接hive。
·基于impyla連接hive。
方法一:使用PyHive庫
安裝依賴包:其中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
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還需要以下兩個(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()
關(guān)于python 如何連接hive就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
分享名稱:python如何連接hive-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://jinyejixie.com/article48/dhdchp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計(jì)公司、服務(wù)器托管、網(wǎng)站建設(shè)、App設(shè)計(jì)、外貿(mào)網(wǎng)站建設(shè)、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容