-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff_check.py
More file actions
45 lines (38 loc) · 1.51 KB
/
diff_check.py
File metadata and controls
45 lines (38 loc) · 1.51 KB
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
import pyodbc
import snowflake.connector
src = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=<sql-server-host>;DATABASE=<source-database>;Trusted_Connection=yes')
tgt = snowflake.connector.connect(
account='<snowflake-account>', user='<user@domain>',
authenticator='externalbrowser', warehouse='<snowflake-warehouse>',
database='<snowflake-database>', schema='<target-schema>', role='<snowflake-role>'
)
tables = [
('SOURCE_TABLE_A', 'TARGET_TABLE_A', 'id'),
('SOURCE_TABLE_B', 'TARGET_TABLE_B', 'name'),
('SOURCE_TABLE_C', 'TARGET_TABLE_C', 'category'),
]
for src_tbl, tgt_tbl, order_col in tables:
print(f"\n{'='*60}")
print(f"TABLE: {src_tbl}")
sc = src.cursor()
sc.execute(f"SELECT TOP 2 * FROM {src_tbl} ORDER BY [{order_col}]")
src_cols = [d[0] for d in sc.description]
src_rows = sc.fetchall()
print(f"SOURCE cols: {src_cols}")
for r in src_rows:
print(f" SRC: {list(r)}")
tc = tgt.cursor()
tc.execute(f'SELECT * FROM <snowflake-database>.<target-schema>.{tgt_tbl} ORDER BY {order_col} LIMIT 2')
tgt_cols = [d[0] for d in tc.description]
tgt_rows = tc.fetchall()
print(f"TARGET cols: {tgt_cols}")
for r in tgt_rows:
print(f" TGT: {list(r)}")
src_set = set(c.upper() for c in src_cols)
tgt_set = set(c.upper() for c in tgt_cols)
if src_set != tgt_set:
print(f" EXTRA in target: {tgt_set - src_set}")
print(f" MISSING in target: {src_set - tgt_set}")
src.close()
tgt.close()
print("\nDONE")