@@ -42,7 +42,6 @@ class RedshiftTable(BaseTable):
42
42
serde_parameters : Optional [str ] = None
43
43
last_altered : Optional [datetime ] = None
44
44
45
- @property
46
45
def is_external_table (self ) -> bool :
47
46
return self .type == "EXTERNAL_TABLE"
48
47
@@ -56,7 +55,6 @@ class RedshiftView(BaseTable):
56
55
size_in_bytes : Optional [int ] = None
57
56
rows_count : Optional [int ] = None
58
57
59
- @property
60
58
def is_external_table (self ) -> bool :
61
59
return self .type == "EXTERNAL_TABLE"
62
60
@@ -71,10 +69,28 @@ class RedshiftSchema:
71
69
external_platform : Optional [str ] = None
72
70
external_database : Optional [str ] = None
73
71
74
- @property
75
72
def is_external_schema (self ) -> bool :
76
73
return self .type == "external"
77
74
75
+ def get_upstream_schema_name (self ) -> Optional [str ]:
76
+ """Gets the schema name from the external schema option.
77
+
78
+ Returns:
79
+ Optional[str]: The schema name from the external schema option
80
+ if this is an external schema and has a valid option format, None otherwise.
81
+ """
82
+
83
+ if not self .is_external_schema () or not self .option :
84
+ return None
85
+
86
+ # For external schema on redshift, option is in form
87
+ # {"SCHEMA":"tickit"}
88
+ schema_match = re .search (r'"SCHEMA"\s*:\s*"([^"]*)"' , self .option )
89
+ if not schema_match :
90
+ return None
91
+ else :
92
+ return schema_match .group (1 )
93
+
78
94
79
95
@dataclass
80
96
class PartialInboundDatashare :
@@ -117,7 +133,6 @@ class RedshiftDatabase:
117
133
type : str
118
134
options : Optional [str ] = None
119
135
120
- @property
121
136
def is_shared_database (self ) -> bool :
122
137
return self .type == "shared"
123
138
@@ -128,7 +143,7 @@ def is_shared_database(self) -> bool:
128
143
def get_inbound_share (
129
144
self ,
130
145
) -> Optional [Union [InboundDatashare , PartialInboundDatashare ]]:
131
- if not self .is_shared_database or not self .options :
146
+ if not self .is_shared_database () or not self .options :
132
147
return None
133
148
134
149
# Convert into single regex ??
@@ -323,6 +338,7 @@ def enrich_tables(
323
338
def get_tables_and_views (
324
339
self ,
325
340
conn : redshift_connector .Connection ,
341
+ database : str ,
326
342
skip_external_tables : bool = False ,
327
343
is_shared_database : bool = False ,
328
344
) -> Tuple [Dict [str , List [RedshiftTable ]], Dict [str , List [RedshiftView ]]]:
@@ -336,6 +352,7 @@ def get_tables_and_views(
336
352
cur = RedshiftDataDictionary .get_query_result (
337
353
conn ,
338
354
RedshiftCommonQuery .list_tables (
355
+ database = database ,
339
356
skip_external_tables = skip_external_tables ,
340
357
is_shared_database = is_shared_database ,
341
358
),
@@ -484,14 +501,17 @@ def get_schema_fields_for_column(
484
501
@staticmethod
485
502
def get_columns_for_schema (
486
503
conn : redshift_connector .Connection ,
504
+ database : str ,
487
505
schema : RedshiftSchema ,
488
506
is_shared_database : bool = False ,
489
507
) -> Dict [str , List [RedshiftColumn ]]:
490
508
cursor = RedshiftDataDictionary .get_query_result (
491
509
conn ,
492
510
RedshiftCommonQuery .list_columns (
493
- is_shared_database = is_shared_database
494
- ).format (schema_name = schema .name ),
511
+ database_name = database ,
512
+ schema_name = schema .name ,
513
+ is_shared_database = is_shared_database ,
514
+ ),
495
515
)
496
516
497
517
table_columns : Dict [str , List [RedshiftColumn ]] = {}
0 commit comments