File tree Expand file tree Collapse file tree 3 files changed +15
-0
lines changed
Expand file tree Collapse file tree 3 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -173,6 +173,7 @@ def __init__(
173173 default_catalog : t .Optional [str ] = None ,
174174 path : Path = Path (),
175175 environment_naming_info : t .Optional [EnvironmentNamingInfo ] = None ,
176+ model_fqn : t .Optional [str ] = None ,
176177 ):
177178 self .dialect = dialect
178179 self .generator = MacroDialect ().generator ()
@@ -198,6 +199,7 @@ def __init__(
198199 self ._snapshots = snapshots if snapshots is not None else {}
199200 self ._path = path
200201 self ._environment_naming_info = environment_naming_info
202+ self ._model_fqn = model_fqn
201203
202204 prepare_env (self .python_env , self .env )
203205 for k , v in self .python_env .items ():
@@ -476,6 +478,12 @@ def this_model(self) -> str:
476478 raise SQLMeshError ("Model name is not available in the macro evaluator." )
477479 return this_model .sql (dialect = self .dialect , identify = True , comments = False )
478480
481+ @property
482+ def this_model_fqn (self ) -> str :
483+ if self ._model_fqn is None :
484+ raise SQLMeshError ("Model name is not available in the macro evaluator." )
485+ return self ._model_fqn
486+
479487 @property
480488 def engine_adapter (self ) -> EngineAdapter :
481489 engine_adapter = self .locals .get ("engine_adapter" )
Original file line number Diff line number Diff line change @@ -169,6 +169,7 @@ def _resolve_table(table: str | exp.Table) -> str:
169169 default_catalog = self ._default_catalog ,
170170 path = self ._path ,
171171 environment_naming_info = environment_naming_info ,
172+ model_fqn = self ._model_fqn ,
172173 )
173174
174175 start_time , end_time = (
Original file line number Diff line number Diff line change @@ -9993,6 +9993,7 @@ def test_extract_schema_in_post_statement(tmp_path: Path) -> None:
99939993 SELECT c FROM x;
99949994 ON_VIRTUAL_UPDATE_BEGIN;
99959995 @check_schema('y');
9996+ @check_self_schema();
99969997 ON_VIRTUAL_UPDATE_END;
99979998 """
99989999 )
@@ -10007,6 +10008,11 @@ def test_extract_schema_in_post_statement(tmp_path: Path) -> None:
1000710008def check_schema(evaluator, model_name: str):
1000810009 if evaluator.runtime_stage != 'loading':
1000910010 assert evaluator.columns_to_types(model_name) == {"c": exp.DataType.build("INT")}
10011+
10012+ @macro()
10013+ def check_self_schema(evaluator):
10014+ if evaluator.runtime_stage != 'loading':
10015+ assert evaluator.columns_to_types(evaluator.this_model_fqn) == {"c": exp.DataType.build("INT")}
1001010016""" )
1001110017
1001210018 context = Context (paths = tmp_path , config = config )
You can’t perform that action at this time.
0 commit comments