标签:dba span sel microsoft lis lse err base cal
Impyla是用于分布式查询引擎的HiveServer2实现(如Impala、Hive)的python客户端
1)安装impyla
pip install impyla
安装报错
解决办法:
根据提示下载对应的工具
https://visualstudio.microsoft.com/zh-hans/downloads/
直接下载安装即可
工具安装完成后,继续pip install impyla
安装成功
代码测试:
from impala.dbapi import connect conn = 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 connect
class 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,"没有设置数据库信息")
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,"连接数据库失败")
else:
return cur
def ExecQuery(self,sql):
cur = self.__GetConnect()
cur.execute(sql)
resList = cur.fetchall()
#查询完毕后必须关闭连接
self.conn.close()
return resList
def ExecNonQuery(self,sql):
cur = self.__GetConnect()
cur.execute(sql)
self.conn.commit()
self.conn.close()
标签:dba span sel microsoft lis lse err base cal
原文地址:https://www.cnblogs.com/kopao/p/13399182.html