Skip to content

Commit da73296

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

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

docs/concepts/macros/sqlmesh_macros.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,36 @@ 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+
1698+
!!! note
1699+
For the "promotion" runtime stage, the model name resolution occurs at 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.
1700+
1701+
#### Accessing the invoking model's unresolved name
1702+
1703+
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.
1704+
1705+
```python linenums="1"
1706+
from sqlmesh.core.macros import macro
1707+
1708+
@macro()
1709+
def some_macro(evaluator):
1710+
resolved_model = evaluator.this_model_fqn # e.g., '"datalake"."landing"."customers"'
1711+
...
1712+
```
1713+
16841714
#### Accessing model schemas
16851715

16861716
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)