Skip to content

Commit cb53f29

Browse files
authored
Chore: update blueprint docs (#4078)
1 parent 15866ba commit cb53f29

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

docs/concepts/macros/sqlmesh_macros.md

+28-4
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ It uses the following five step approach to accomplish this:
4141

4242
## User-defined variables
4343

44-
SQLMesh supports three kinds of user-defined macro variables: [global](#global-variables), [gateway](#gateway-variables), and [local](#local-variables).
44+
SQLMesh supports four kinds of user-defined macro variables: [global](#global-variables), [gateway](#gateway-variables), [blueprint](#blueprint-variables) and [local](#local-variables).
4545

46-
Global and gateway macro variables are defined in the project configuration file and can be accessed in any project model. Local macro variables are defined in a model definition and can only be accessed in that model.
46+
Global and gateway macro variables are defined in the project configuration file and can be accessed in any project model. Blueprint and macro variables are defined in a model definition and can only be accessed in that model.
4747

48-
Macro variables with the same name may be specified at any or all of the global, gateway, and local levels. When variables are specified at multiple levels, the value of the most specific level takes precedence. For example, the value of a local variable takes precedence over the value of a gateway variable with the same name, and the value of a gateway variable takes precedence over the value of a global variable.
48+
Macro variables with the same name may be specified at any or all of the global, gateway, blueprint and local levels. When variables are specified at multiple levels, the value of the most specific level takes precedence. For example, the value of a local variable takes precedence over the value of a blueprint or gateway variable with the same name, and the value of a gateway variable takes precedence over the value of a global variable.
4949

5050
### Global variables
5151

@@ -152,9 +152,33 @@ Access them in models using the same methods as [global variables](#global-varia
152152

153153
Gateway-specific variable values take precedence over variables with the same name specified in the root `variables` key.
154154

155+
### Blueprint variables
156+
157+
Blueprint macro variables are defined in a model. Blueprint variable values take precedence over [global](#global-variables) or [gateway-specific](#gateway-variables) variables with the same name.
158+
159+
Blueprint variables are defined as a property of the `MODEL` statement, and serve as a mechanism for [creating model templates](../models/sql_models.md):
160+
161+
```sql linenums="1"
162+
MODEL (
163+
name @customer.some_table,
164+
kind FULL,
165+
blueprints (
166+
(customer := customer1, field_a := x, field_b := y),
167+
(customer := customer2, field_a := z, field_b := w)
168+
)
169+
);
170+
171+
SELECT
172+
@field_a,
173+
@{field_b} AS field_b
174+
FROM @customer.some_source
175+
```
176+
177+
Blueprint variables can be accessed using the syntax shown above, or through the `@BLUEPRINT_VAR()` macro function, which also supports specifying default values in case the variable is undefined (similar to `@VAR()`).
178+
155179
### Local variables
156180

157-
Local macro variables are defined in a model. Local variable values take precedence over [global](#global-variables) or [gateway-specific](#gateway-variables) variables with the same name.
181+
Local macro variables are defined in a model. Local variable values take precedence over [global](#global-variables), [blueprint](#blueprint-variables), or [gateway-specific](#gateway-variables) variables with the same name.
158182

159183
Define your own local macro variables with the `@DEF` macro operator. For example, you could set the macro variable `macro_var` to the value `1` with:
160184

docs/concepts/models/python_models.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,9 @@ def entrypoint(
360360
) -> pd.DataFrame:
361361
return pd.DataFrame(
362362
{
363-
"field_a": [context.var("field_a")],
364-
"field_b": [context.var("field_b")],
365-
"customer": [context.var("customer")],
363+
"field_a": [context.blueprint_var("field_a")],
364+
"field_b": [context.blueprint_var("field_b")],
365+
"customer": [context.blueprint_var("customer")],
366366
}
367367
)
368368
```

docs/concepts/models/sql_models.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ from sqlmesh.core.macros import MacroEvaluator
249249
],
250250
)
251251
def entrypoint(evaluator: MacroEvaluator) -> str | exp.Expression:
252-
field_a = evaluator.var("field_a")
253-
field_b = evaluator.var("field_b")
254-
customer = evaluator.var("customer")
252+
field_a = evaluator.blueprint_var("field_a")
253+
field_b = evaluator.blueprint_var("field_b")
254+
customer = evaluator.blueprint_var("customer")
255255

256256
return exp.select(field_a, field_b).from_(f"{customer}.some_source")
257257
```

0 commit comments

Comments
 (0)