dbt-cube-sync 0.1.0a6__tar.gz → 0.1.0a7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dbt_cube_sync-0.1.0a6 → dbt_cube_sync-0.1.0a7}/PKG-INFO +1 -1
- dbt_cube_sync-0.1.0a7/dbt_cube_sync/core/db_inspector.py +112 -0
- {dbt_cube_sync-0.1.0a6 → dbt_cube_sync-0.1.0a7}/pyproject.toml +1 -1
- dbt_cube_sync-0.1.0a6/dbt_cube_sync/core/db_inspector.py +0 -51
- {dbt_cube_sync-0.1.0a6 → dbt_cube_sync-0.1.0a7}/README.md +0 -0
- {dbt_cube_sync-0.1.0a6 → dbt_cube_sync-0.1.0a7}/dbt_cube_sync/__init__.py +0 -0
- {dbt_cube_sync-0.1.0a6 → dbt_cube_sync-0.1.0a7}/dbt_cube_sync/cli.py +0 -0
- {dbt_cube_sync-0.1.0a6 → dbt_cube_sync-0.1.0a7}/dbt_cube_sync/config.py +0 -0
- {dbt_cube_sync-0.1.0a6 → dbt_cube_sync-0.1.0a7}/dbt_cube_sync/connectors/__init__.py +0 -0
- {dbt_cube_sync-0.1.0a6 → dbt_cube_sync-0.1.0a7}/dbt_cube_sync/connectors/base.py +0 -0
- {dbt_cube_sync-0.1.0a6 → dbt_cube_sync-0.1.0a7}/dbt_cube_sync/connectors/powerbi.py +0 -0
- {dbt_cube_sync-0.1.0a6 → dbt_cube_sync-0.1.0a7}/dbt_cube_sync/connectors/superset.py +0 -0
- {dbt_cube_sync-0.1.0a6 → dbt_cube_sync-0.1.0a7}/dbt_cube_sync/connectors/tableau.py +0 -0
- {dbt_cube_sync-0.1.0a6 → dbt_cube_sync-0.1.0a7}/dbt_cube_sync/core/__init__.py +0 -0
- {dbt_cube_sync-0.1.0a6 → dbt_cube_sync-0.1.0a7}/dbt_cube_sync/core/cube_generator.py +0 -0
- {dbt_cube_sync-0.1.0a6 → dbt_cube_sync-0.1.0a7}/dbt_cube_sync/core/dbt_parser.py +0 -0
- {dbt_cube_sync-0.1.0a6 → dbt_cube_sync-0.1.0a7}/dbt_cube_sync/core/models.py +0 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Database inspector - fetches column types using SQLAlchemy
|
|
3
|
+
"""
|
|
4
|
+
from typing import Dict, Optional
|
|
5
|
+
from sqlalchemy import create_engine, inspect, MetaData, Table, text
|
|
6
|
+
from sqlalchemy.engine import Engine
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class DatabaseInspector:
|
|
10
|
+
"""Inspects database schema to extract column type information"""
|
|
11
|
+
|
|
12
|
+
def __init__(self, sqlalchemy_uri: str):
|
|
13
|
+
"""
|
|
14
|
+
Initialize the database inspector
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
sqlalchemy_uri: SQLAlchemy connection URI (e.g., postgresql://user:pass@host:port/db)
|
|
18
|
+
"""
|
|
19
|
+
# Add connect_args for Redshift compatibility
|
|
20
|
+
if 'redshift' in sqlalchemy_uri:
|
|
21
|
+
self.engine: Engine = create_engine(
|
|
22
|
+
sqlalchemy_uri,
|
|
23
|
+
connect_args={'sslmode': 'prefer'}
|
|
24
|
+
)
|
|
25
|
+
else:
|
|
26
|
+
self.engine: Engine = create_engine(sqlalchemy_uri)
|
|
27
|
+
|
|
28
|
+
self.inspector = inspect(self.engine)
|
|
29
|
+
self.is_redshift = 'redshift' in sqlalchemy_uri.lower()
|
|
30
|
+
|
|
31
|
+
def get_table_columns(self, schema: str, table_name: str) -> Dict[str, str]:
|
|
32
|
+
"""
|
|
33
|
+
Get column names and their data types for a specific table
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
schema: Database schema name
|
|
37
|
+
table_name: Table name
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
Dictionary mapping column names to data types
|
|
41
|
+
"""
|
|
42
|
+
columns = {}
|
|
43
|
+
|
|
44
|
+
try:
|
|
45
|
+
# For Redshift, use direct SQL query to avoid pg_catalog issues
|
|
46
|
+
if self.is_redshift:
|
|
47
|
+
columns = self._get_redshift_columns(schema, table_name)
|
|
48
|
+
else:
|
|
49
|
+
# Get columns from the database using inspector
|
|
50
|
+
table_columns = self.inspector.get_columns(table_name, schema=schema)
|
|
51
|
+
|
|
52
|
+
for column in table_columns:
|
|
53
|
+
col_name = column['name']
|
|
54
|
+
col_type = str(column['type'])
|
|
55
|
+
columns[col_name] = col_type
|
|
56
|
+
|
|
57
|
+
except Exception as e:
|
|
58
|
+
print(f"Warning: Could not inspect table {schema}.{table_name}: {e}")
|
|
59
|
+
|
|
60
|
+
return columns
|
|
61
|
+
|
|
62
|
+
def _get_redshift_columns(self, schema: str, table_name: str) -> Dict[str, str]:
|
|
63
|
+
"""
|
|
64
|
+
Get columns for Redshift using direct SQL query
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
schema: Database schema name
|
|
68
|
+
table_name: Table name
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
Dictionary mapping column names to data types
|
|
72
|
+
"""
|
|
73
|
+
columns = {}
|
|
74
|
+
|
|
75
|
+
try:
|
|
76
|
+
# Query Redshift's pg_table_def view which is more reliable
|
|
77
|
+
query = text("""
|
|
78
|
+
SELECT column_name, data_type
|
|
79
|
+
FROM pg_table_def
|
|
80
|
+
WHERE schemaname = :schema
|
|
81
|
+
AND tablename = :table_name
|
|
82
|
+
ORDER BY column_name
|
|
83
|
+
""")
|
|
84
|
+
|
|
85
|
+
with self.engine.connect() as conn:
|
|
86
|
+
result = conn.execute(query, {"schema": schema, "table_name": table_name})
|
|
87
|
+
for row in result:
|
|
88
|
+
columns[row[0]] = row[1]
|
|
89
|
+
|
|
90
|
+
except Exception as e:
|
|
91
|
+
# Fallback to information_schema if pg_table_def fails
|
|
92
|
+
try:
|
|
93
|
+
query = text("""
|
|
94
|
+
SELECT column_name, data_type
|
|
95
|
+
FROM information_schema.columns
|
|
96
|
+
WHERE table_schema = :schema
|
|
97
|
+
AND table_name = :table_name
|
|
98
|
+
ORDER BY ordinal_position
|
|
99
|
+
""")
|
|
100
|
+
|
|
101
|
+
with self.engine.connect() as conn:
|
|
102
|
+
result = conn.execute(query, {"schema": schema, "table_name": table_name})
|
|
103
|
+
for row in result:
|
|
104
|
+
columns[row[0]] = row[1]
|
|
105
|
+
except Exception as fallback_error:
|
|
106
|
+
print(f"Warning: Could not query Redshift table {schema}.{table_name}: {fallback_error}")
|
|
107
|
+
|
|
108
|
+
return columns
|
|
109
|
+
|
|
110
|
+
def close(self):
|
|
111
|
+
"""Close the database connection"""
|
|
112
|
+
self.engine.dispose()
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Database inspector - fetches column types using SQLAlchemy
|
|
3
|
-
"""
|
|
4
|
-
from typing import Dict, Optional
|
|
5
|
-
from sqlalchemy import create_engine, inspect, MetaData, Table
|
|
6
|
-
from sqlalchemy.engine import Engine
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class DatabaseInspector:
|
|
10
|
-
"""Inspects database schema to extract column type information"""
|
|
11
|
-
|
|
12
|
-
def __init__(self, sqlalchemy_uri: str):
|
|
13
|
-
"""
|
|
14
|
-
Initialize the database inspector
|
|
15
|
-
|
|
16
|
-
Args:
|
|
17
|
-
sqlalchemy_uri: SQLAlchemy connection URI (e.g., postgresql://user:pass@host:port/db)
|
|
18
|
-
"""
|
|
19
|
-
self.engine: Engine = create_engine(sqlalchemy_uri)
|
|
20
|
-
self.inspector = inspect(self.engine)
|
|
21
|
-
|
|
22
|
-
def get_table_columns(self, schema: str, table_name: str) -> Dict[str, str]:
|
|
23
|
-
"""
|
|
24
|
-
Get column names and their data types for a specific table
|
|
25
|
-
|
|
26
|
-
Args:
|
|
27
|
-
schema: Database schema name
|
|
28
|
-
table_name: Table name
|
|
29
|
-
|
|
30
|
-
Returns:
|
|
31
|
-
Dictionary mapping column names to data types
|
|
32
|
-
"""
|
|
33
|
-
columns = {}
|
|
34
|
-
|
|
35
|
-
try:
|
|
36
|
-
# Get columns from the database
|
|
37
|
-
table_columns = self.inspector.get_columns(table_name, schema=schema)
|
|
38
|
-
|
|
39
|
-
for column in table_columns:
|
|
40
|
-
col_name = column['name']
|
|
41
|
-
col_type = str(column['type'])
|
|
42
|
-
columns[col_name] = col_type
|
|
43
|
-
|
|
44
|
-
except Exception as e:
|
|
45
|
-
print(f"Warning: Could not inspect table {schema}.{table_name}: {e}")
|
|
46
|
-
|
|
47
|
-
return columns
|
|
48
|
-
|
|
49
|
-
def close(self):
|
|
50
|
-
"""Close the database connection"""
|
|
51
|
-
self.engine.dispose()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|