Skip to content

Commit 8e13c49

Browse files
committed
Chore: document this_model and this_model_fqn
1 parent ab4df0f commit 8e13c49

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

docs/concepts/macros/sqlmesh_macros.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,35 @@ def some_macro(evaluator):
16811681
...
16821682
```
16831683

1684+
#### Accessing the invoking model's resolved name
1685+
1686+
The physical table name of the invoking model can be accessed within a Python macro function through its evaluation context's `this_model` property.
1687+
1688+
```python linenums="1"
1689+
from sqlmesh.core.macros import macro
1690+
1691+
@macro()
1692+
def some_macro(evaluator):
1693+
resolved_model = evaluator.this_model # e.g., '"datalake"."sqlmesh__landing"."landing__customers__2517971505"'
1694+
...
1695+
```
1696+
1697+
!!! note
1698+
During the "promotion" runtime stage, the model name resolution occurs for the virtual layer. This means that `this_model` resolve to the qualified view name of the invoking model. For instance, when running the plan in an environment named `dev`, `db.test_model` and `this_model` would resolve to `'"db__dev"."test_model"'` and not to the physical table name.
1699+
1700+
#### Accessing the invoking model's unresolved name
1701+
1702+
The unresolved, fully-qualified name of the invoking model can be accessed within a Python macro function through its evaluation context's `this_model_fqn` property.
1703+
1704+
```python linenums="1"
1705+
from sqlmesh.core.macros import macro
1706+
1707+
@macro()
1708+
def some_macro(evaluator):
1709+
resolved_model = evaluator.this_model_fqn # e.g., '"datalake"."landing"."customers"'
1710+
...
1711+
```
1712+
16841713
#### Accessing model schemas
16851714

16861715
Model schemas can be accessed within a Python macro function through its evaluation context's `column_to_types()` method, if the column types can be statically determined. For instance, a schema of an [external model](../models/external_models.md) can be accessed only after the `sqlmesh create_external_models` command has been executed.

0 commit comments

Comments
 (0)