-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathctrl_impala.py
More file actions
35 lines (27 loc) · 743 Bytes
/
ctrl_impala.py
File metadata and controls
35 lines (27 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2020/5/27 13:38
# @Author : way
# @Site :
# @Describe: 操作 impala
from impala.dbapi import connect
class CtrlImpala:
def __init__(self, host, port):
self.connection = connect(host=host, port=port)
def __del__(self):
self.connection.close()
def execute(self, sql):
with self.connection.cursor() as cursor:
cursor.execute(sql)
try:
rows = cursor.fetchall()
return rows
except:
pass
if __name__ == "__main__":
host = '172.16.122.26'
port = 21050
im = CtrlImpala(host, port)
sql = "show databases;"
rows = im.execute(sql)
print(rows)