Python連接Impala實(shí)現(xiàn)步驟解析
Impyla是用于分布式查詢引擎的HiveServer2實(shí)現(xiàn)(如Impala、Hive)的python客戶端
1)安裝impyla
pip install impyla
安裝報(bào)錯(cuò)
解決辦法:
根據(jù)提示下載對(duì)應(yīng)的工具
https://visualstudio.microsoft.com/zh-hans/downloads/
直接下載安裝即可
工具安裝完成后,繼續(xù)pip install impyla
安裝成功
代碼測(cè)試:
from impala.dbapi import connectconn = connect(host=’xxx.xxx.xxx.xxx’, port=21050)cur = conn.cursor()cur.execute(’show databases;’)database_list=cur.fetchall()for data in database_list: print(data)
OK 正常連接
參照以前的Mysql連接工具類,寫了個(gè)連接Impala的工具類:
from impala.dbapi import connectclass IMPALA: def __init__(self,host,port,user,pwd,db): self.host = host self.port = port self.user = user self.pwd = pwd self.db = db def __GetConnect(self): if not self.db: raise(NameError,'沒有設(shè)置數(shù)據(jù)庫(kù)信息') self.conn = connect(host=self.host,port=self.port,user=self.user,password=self.pwd,database=self.db) cur = self.conn.cursor() if not cur: raise(NameError,'連接數(shù)據(jù)庫(kù)失敗') else: return cur def ExecQuery(self,sql): cur = self.__GetConnect() cur.execute(sql) resList = cur.fetchall() #查詢完畢后必須關(guān)閉連接 self.conn.close() return resList def ExecNonQuery(self,sql): cur = self.__GetConnect() cur.execute(sql) self.conn.commit() self.conn.close()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 低版本IE正常運(yùn)行HTML5+CSS3網(wǎng)站的3種解決方案2. ASP.NET泛型三之使用協(xié)變和逆變實(shí)現(xiàn)類型轉(zhuǎn)換3. JSP數(shù)據(jù)交互實(shí)現(xiàn)過程解析4. jsp+servlet簡(jiǎn)單實(shí)現(xiàn)上傳文件功能(保存目錄改進(jìn))5. 如何在jsp界面中插入圖片6. XML基本概念XPath、XSLT與XQuery函數(shù)介紹7. JS中map和parseInt的用法詳解8. PHP循環(huán)與分支知識(shí)點(diǎn)梳理9. AspNetCore&MassTransit Courier實(shí)現(xiàn)分布式事務(wù)的詳細(xì)過程10. jsp實(shí)現(xiàn)登錄界面
