@@ -13,6 +13,7 @@ def __init__(
1313 self ,
1414 event_timestamp_column : Optional [str ] = "" ,
1515 table : Optional [str ] = None ,
16+ schema : Optional [str ] = None ,
1617 created_timestamp_column : Optional [str ] = "" ,
1718 field_mapping : Optional [Dict [str , str ]] = None ,
1819 date_partition_column : Optional [str ] = "" ,
@@ -25,7 +26,7 @@ def __init__(
2526 date_partition_column ,
2627 )
2728
28- self ._redshift_options = RedshiftOptions (table = table , query = query )
29+ self ._redshift_options = RedshiftOptions (table = table , schema = schema , query = query )
2930
3031 @staticmethod
3132 def from_proto (data_source : DataSourceProto ):
@@ -95,7 +96,8 @@ def validate(self, config: RepoConfig):
9596 def get_table_query_string (self ) -> str :
9697 """Returns a string that can directly be used to reference this table in SQL"""
9798 if self .table :
98- return f'"{ self .table } "'
99+ schema_prefix = f'{ self .schema } .' if self .schema is not None else ''
100+ return f'"{ schema_prefix } { self .table } "'
99101 else :
100102 return f"({ self .query } )"
101103
@@ -153,9 +155,19 @@ class RedshiftOptions:
153155 DataSource Redshift options used to source features from Redshift query
154156 """
155157
156- def __init__ (self , table : Optional [str ], query : Optional [str ]):
158+ def __init__ (self , table : Optional [str ], query : Optional [str ], schema : Optional [str ]):
159+ """Redshift options to encapsulate logic for parsing and working with 2 kinds of source creation
160+ table + schema or query
161+
162+ Args:
163+ table (Optional[str]): Redshift table to be looked for in redshift cluster to form datasource
164+ query (Optional[str]): Query to run to gather datasource
165+ schema (Optional[str]): Schema in redshift cluster to lookup a table.
166+ Has to be provided in case of tables with same name.
167+ """
157168 self ._table = table
158169 self ._query = query
170+ self ._schema = schema
159171
160172 @property
161173 def query (self ):
@@ -185,6 +197,20 @@ def table(self, table_name):
185197 """
186198 self ._table = table_name
187199
200+ @property
201+ def schema (self ):
202+ """
203+ Returns the schema name of this Redshift table schema
204+ """
205+ return self ._schema
206+
207+ @schema .setter
208+ def table (self , schema_name ):
209+ """
210+ Sets the schema ref of this Redshift table schema
211+ """
212+ self ._schema = schema_name
213+
188214 @classmethod
189215 def from_proto (cls , redshift_options_proto : DataSourceProto .RedshiftOptions ):
190216 """
@@ -198,7 +224,9 @@ def from_proto(cls, redshift_options_proto: DataSourceProto.RedshiftOptions):
198224 """
199225
200226 redshift_options = cls (
201- table = redshift_options_proto .table , query = redshift_options_proto .query ,
227+ table = redshift_options_proto .table ,
228+ query = redshift_options_proto .query ,
229+ schema = redshift_options_proto .schema
202230 )
203231
204232 return redshift_options
@@ -212,7 +240,7 @@ def to_proto(self) -> DataSourceProto.RedshiftOptions:
212240 """
213241
214242 redshift_options_proto = DataSourceProto .RedshiftOptions (
215- table = self .table , query = self .query ,
243+ table = self .table , query = self .query , schema = self . schema
216244 )
217245
218246 return redshift_options_proto
0 commit comments