Python連接Impala實(shí)現(xiàn)步驟解析
Impyla是用于分布式查詢引擎的HiveServer2實(shí)現(xiàn)(如Impala、Hive)的python客戶端
1)安裝impyla
pip install impyla
安裝報錯
解決辦法:
根據(jù)提示下載對應(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連接工具類,寫了個連接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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP基礎(chǔ)知識VBScript基本元素講解2. ajax請求添加自定義header參數(shù)代碼3. Kotlin + Flow 實(shí)現(xiàn)Android 應(yīng)用初始化任務(wù)啟動庫4. Python requests庫參數(shù)提交的注意事項(xiàng)總結(jié)5. 基于javascript處理二進(jìn)制圖片流過程詳解6. Gitlab CI-CD自動化部署SpringBoot項(xiàng)目的方法步驟7. 解決android studio引用遠(yuǎn)程倉庫下載慢(JCenter下載慢)8. asp知識整理筆記4(問答模式)9. axios和ajax的區(qū)別點(diǎn)總結(jié)10. 詳談ajax返回數(shù)據(jù)成功 卻進(jìn)入error的方法
