新聞中心
這篇文章主要介紹了如何使用Python Impyla客戶端連接Hive和Impala,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
創(chuàng)新互聯(lián)公司堅(jiān)信:善待客戶,將會(huì)成為終身客戶。我們能堅(jiān)持多年,是因?yàn)槲覀円恢笨芍档眯刨嚒N覀儚牟缓鲇瞥踉L客戶,我們用心做好本職工作,不忘初心,方得始終。十年網(wǎng)站建設(shè)經(jīng)驗(yàn)創(chuàng)新互聯(lián)公司是成都老牌網(wǎng)站營銷服務(wù)商,為您提供網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、網(wǎng)站設(shè)計(jì)、H5場(chǎng)景定制、網(wǎng)站制作、成都品牌網(wǎng)站建設(shè)、小程序設(shè)計(jì)服務(wù),給眾多知名企業(yè)提供過好品質(zhì)的建站服務(wù)。
使用hive模塊
pip install sasl
pip install thrift
pip install thrift-sasl
pip install PyHive
[root@ip-172-31-40-242 ~]# more testpyhive.py
from pyhive import hive
conn = hive.Connection(host='xxxxxxx', port=10000, database='collection',username='')
cursor=conn.cursor()
cursor.execute('select * from tb_partition limit 10')
for result in cursor.fetchall():
print result
[root@ip-172-31-40-242 ~]# python testpyhive.py
(u'1', u'2', u'201707')
(u'1', u'2', u'201707')
(u'123', None, u'201709')
(u'123', u'456', u'201709')
(u'45678', u'456', u'201709')
(u'123', None, u'201709')
(u'123', u'456', u'201709')
(u'45678', u'456', u'201709')
(u'123', None, u'201709')
(u'123', u'456', u'201709')
官方API:
https://pypi.org/project/PyHive/
如何使用Python Impyla客戶端連接Hive和Impala
# -*- coding:utf-8 -*- from impala.dbapi import connect conn = connect(host='172.31.46.109',port=10000,database='collection',auth_mechanism='PLAIN') print(conn) cursor = conn.cursor() # param = '''SET hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager; SET hive.support.concurrency=true; ''' cursor.execute(param) cursor.execute('SELECT uid FROM redefine_collection where uid=4028 limit 10') print cursor.description # prints the result set's schema results = cursor.fetchall() print results # # Python連接Impala(ImpalaTest.py) # # from impala.dbapi importconnect # # conn = connect(host='ip-172-31-26-80.ap-southeast-1.compute.internal',port=21050) # # print(conn) # # cursor = conn.cursor() # # cursor.execute('show databases') # # print cursor.description # prints the result set's schema # # results = cursor.fetchall() # # print(results) # # cursor.execute('SELECT * FROM test limit 10') # # print cursor.description # prints the result set's schema # # results = cursor.fetchall() # # print(results)
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“如何使用Python Impyla客戶端連接Hive和Impala”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!
網(wǎng)站題目:如何使用PythonImpyla客戶端連接Hive和Impala
當(dāng)前URL:http://www.ef60e0e.cn/article/gdggih.html