@@ -29,12 +29,12 @@ def __init__(
2929 self ,
3030 jinja_macros : JinjaMacroRegistry ,
3131 jinja_globals : t .Optional [t .Dict [str , t .Any ]] = None ,
32- dialect : t .Optional [str ] = None ,
32+ project_dialect : t .Optional [str ] = None ,
3333 ):
3434 self .jinja_macros = jinja_macros
3535 self .jinja_globals = jinja_globals .copy () if jinja_globals else {}
3636 self .jinja_globals ["adapter" ] = self
37- self .dialect = dialect
37+ self .project_dialect = project_dialect
3838
3939 @abc .abstractmethod
4040 def get_relation (self , database : str , schema : str , identifier : str ) -> t .Optional [BaseRelation ]:
@@ -93,7 +93,7 @@ def resolve_identifier(self, relation: BaseRelation) -> t.Optional[str]:
9393
9494 def quote (self , identifier : str ) -> str :
9595 """Returns a quoted identifier."""
96- return exp .to_column (identifier ).sql (dialect = self .dialect , identify = True )
96+ return exp .to_column (identifier ).sql (dialect = self .project_dialect , identify = True )
9797
9898 def dispatch (self , name : str , package : t .Optional [str ] = None ) -> t .Callable :
9999 """Returns a dialect-specific version of a macro with the given name."""
@@ -189,12 +189,17 @@ def __init__(
189189 snapshots : t .Optional [t .Dict [str , Snapshot ]] = None ,
190190 table_mapping : t .Optional [t .Dict [str , str ]] = None ,
191191 deployability_index : t .Optional [DeployabilityIndex ] = None ,
192+ project_dialect : t .Optional [str ] = None ,
192193 ):
193194 from dbt .adapters .base import BaseRelation
194195 from dbt .adapters .base .column import Column
195196 from dbt .adapters .base .relation import Policy
196197
197- super ().__init__ (jinja_macros , jinja_globals = jinja_globals , dialect = engine_adapter .dialect )
198+ super ().__init__ (
199+ jinja_macros ,
200+ jinja_globals = jinja_globals ,
201+ project_dialect = project_dialect or engine_adapter .dialect ,
202+ )
198203
199204 table_mapping = table_mapping or {}
200205
@@ -259,7 +264,9 @@ def get_columns_in_relation(self, relation: BaseRelation) -> t.List[Column]:
259264
260265 mapped_table = self ._map_table_name (self ._normalize (self ._relation_to_table (relation )))
261266 return [
262- Column .from_description (name = name , raw_data_type = dtype .sql (dialect = self .dialect ))
267+ Column .from_description (
268+ name = name , raw_data_type = dtype .sql (dialect = self .project_dialect )
269+ )
263270 for name , dtype in self .engine_adapter .columns (table_name = mapped_table ).items ()
264271 ]
265272
@@ -298,12 +305,12 @@ def execute(
298305 self .engine_adapter .fetchdf if fetch else self .engine_adapter .execute # type: ignore
299306 )
300307
301- expression = parse_one (sql , read = self .dialect )
308+ expression = parse_one (sql , read = self .project_dialect )
302309 with normalize_and_quote (
303- expression , t .cast (str , self .dialect ), self .engine_adapter .default_catalog
310+ expression , t .cast (str , self .project_dialect ), self .engine_adapter .default_catalog
304311 ) as expression :
305312 expression = exp .replace_tables (
306- expression , self .table_mapping , dialect = self .dialect , copy = False
313+ expression , self .table_mapping , dialect = self .project_dialect , copy = False
307314 )
308315
309316 if auto_begin :
@@ -328,17 +335,17 @@ def resolve_identifier(self, relation: BaseRelation) -> t.Optional[str]:
328335 return identifier if identifier else None
329336
330337 def _map_table_name (self , table : exp .Table ) -> exp .Table :
331- name = table .sql ()
338+ name = table .sql (dialect = self . project_dialect )
332339 physical_table_name = self .table_mapping .get (name )
333340 if not physical_table_name :
334341 return table
335342
336343 logger .debug ("Resolved ref '%s' to snapshot table '%s'" , name , physical_table_name )
337344
338- return exp .to_table (physical_table_name , dialect = self .dialect )
345+ return exp .to_table (physical_table_name , dialect = self .project_dialect )
339346
340347 def _relation_to_table (self , relation : BaseRelation ) -> exp .Table :
341- return exp .to_table (relation .render (), dialect = self .dialect )
348+ return exp .to_table (relation .render (), dialect = self .project_dialect )
342349
343350 def _table_to_relation (self , table : exp .Table ) -> BaseRelation :
344351 return self .relation_type .create (
@@ -358,7 +365,7 @@ def _schema(self, schema_relation: BaseRelation) -> exp.Table:
358365
359366 def _normalize (self , input_table : exp .Table ) -> exp .Table :
360367 normalized_name = normalize_model_name (
361- input_table , self .engine_adapter .default_catalog , self .dialect
368+ input_table , self .engine_adapter .default_catalog , self .project_dialect
362369 )
363370 normalized_table = exp .to_table (normalized_name )
364371 if not input_table .this :
0 commit comments