-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathctrl_hive.py
More file actions
35 lines (27 loc) · 856 Bytes
/
ctrl_hive.py
File metadata and controls
35 lines (27 loc) · 856 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 17:23
# @Author : way
# @Site :
# @Describe: 操作 hive , windows 下可能会有环境问题,参考 https://www.cnblogs.com/TurboWay/p/12975034.html
from impala.dbapi import connect
class CtrlHive:
def __init__(self, host, port):
self.connection = connect(host=host, port=port, auth_mechanism='PLAIN')
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.20'
port = 10000
hv = CtrlHive(host, port)
sql = "show databases"
rows = hv.execute(sql)
print(rows)