-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyse_insertion.py
51 lines (44 loc) · 1.48 KB
/
analyse_insertion.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import configparser
import psycopg2
from sql_queries import analyze_queries
def analyze_tables_queries(cur):
"""Analyze the fact and dimension queries
Args:
cur (obj): [The database connection cursor to perform sql query execution]
"""
print("Starting to analyze some queries")
for query in analyze_queries:
cur.execute(query)
rows = cur.fetchall()
print(f"--------------------- SQL ----------------------------")
print(f"{query}")
for row in rows:
print(f"--------------------- ROW INFO -----------------------")
print(f"{row}")
def main():
"""The main wrapper function which first initializes the configuration and calls the analysis query function to analyse
the fact and dimension table insertions.
"""
config = configparser.ConfigParser()
config.read("dwh.cfg")
HOST = config.get("CLUSTER", "HOST")
DB_NAME = config.get("CLUSTER", "DB_NAME")
DB_USER = config.get("CLUSTER", "DB_USER")
DB_PASSWORD = config.get("CLUSTER", "DB_PASSWORD")
DB_PORT = config.get("CLUSTER", "DB_PORT")
conn = psycopg2.connect(
host=HOST,
dbname=DB_NAME,
user=DB_USER,
password=DB_PASSWORD,
port=DB_PORT,
# keepalives=1,
# keepalives_idle=30,
# keepalives_interval=10,
# keepalives_count=5
)
cur = conn.cursor()
analyze_tables_queries(cur)
conn.close()
if __name__ == "__main__":
main()