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
安裝成功
代碼測試:
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ù)庫信息') 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ù)庫失敗') 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()
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. el-input無法輸入的問題和表單驗(yàn)證失敗問題解決2. 不要在HTML中濫用div3. react腳手架配置代理的實(shí)現(xiàn)4. JavaScript中顏色模型的基礎(chǔ)知識(shí)與應(yīng)用詳解5. XML 增、刪、改和查示例6. JavaScript快速實(shí)現(xiàn)一個(gè)顏色選擇器7. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)8. XML入門的常見問題(三)9. 前端html+css實(shí)現(xiàn)動(dòng)態(tài)生日快樂代碼10. React實(shí)現(xiàn)一個(gè)倒計(jì)時(shí)hook組件實(shí)戰(zhàn)示例
