|
2 | 2 |
|
3 | 3 | This guide describes how to select specific models to include in a SQLMesh plan, which can be useful when modifying a subset of the models in a SQLMesh project.
|
4 | 4 |
|
5 |
| -Note: the selector syntax described below is also used for the SQLMesh `plan` [`--allow-destructive-model` selector](../concepts/plans.md#destructive-changes). |
| 5 | +Note: the selector syntax described below is also used for the SQLMesh `plan` [`--allow-destructive-model` selector](../concepts/plans.md#destructive-changes) and for the `table_diff` command to [diff a selection of models](./tablediff.md#diffing-multiple-models-across-environments). |
6 | 6 |
|
7 | 7 | ## Background
|
8 | 8 |
|
@@ -221,6 +221,81 @@ Models:
|
221 | 221 | └── sushi.customer_revenue_lifetime
|
222 | 222 | ```
|
223 | 223 |
|
| 224 | +#### Select with tags |
| 225 | + |
| 226 | +If we specify the `--select-model` option with a tag selector like `"tag:reporting"`, all models with the "reporting" tag will be selected. Tags are case-insensitive and support wildcards: |
| 227 | + |
| 228 | +```bash |
| 229 | +❯ sqlmesh plan dev --select-model "tag:reporting*" |
| 230 | +New environment `dev` will be created from `prod` |
| 231 | + |
| 232 | +Differences from the `prod` environment: |
| 233 | + |
| 234 | +Models: |
| 235 | +├── Directly Modified: |
| 236 | +│ ├── sushi.daily_revenue |
| 237 | +│ └── sushi.monthly_revenue |
| 238 | +└── Indirectly Modified: |
| 239 | + └── sushi.revenue_dashboard |
| 240 | +``` |
| 241 | + |
| 242 | +#### Select with git changes |
| 243 | + |
| 244 | +The git-based selector allows you to select models whose files have changed compared to a target branch (default: main). This includes: |
| 245 | +- Untracked files (new files not in git) |
| 246 | +- Uncommitted changes in working directory |
| 247 | +- Committed changes different from the target branch |
| 248 | + |
| 249 | +For example: |
| 250 | + |
| 251 | +```bash |
| 252 | +❯ sqlmesh plan dev --select-model "git:feature" |
| 253 | +New environment `dev` will be created from `prod` |
| 254 | + |
| 255 | +Differences from the `prod` environment: |
| 256 | + |
| 257 | +Models: |
| 258 | +├── Directly Modified: |
| 259 | +│ └── sushi.items # Changed in feature branch |
| 260 | +└── Indirectly Modified: |
| 261 | + ├── sushi.order_items |
| 262 | + └── sushi.daily_revenue |
| 263 | +``` |
| 264 | + |
| 265 | +You can also combine git selection with upstream/downstream indicators: |
| 266 | + |
| 267 | +```bash |
| 268 | +❯ sqlmesh plan dev --select-model "git:feature+" |
| 269 | +# Selects changed models and their downstream dependencies |
| 270 | + |
| 271 | +❯ sqlmesh plan dev --select-model "+git:feature" |
| 272 | +# Selects changed models and their upstream dependencies |
| 273 | +``` |
| 274 | + |
| 275 | +#### Complex selections with logical operators |
| 276 | + |
| 277 | +The model selector supports combining multiple conditions using logical operators: |
| 278 | + |
| 279 | +- `&` (AND): Both conditions must be true |
| 280 | +- `|` (OR): Either condition must be true |
| 281 | +- `^` (NOT): Negates a condition |
| 282 | + |
| 283 | +For example: |
| 284 | + |
| 285 | +```bash |
| 286 | +❯ sqlmesh plan dev --select-model "(tag:finance & ^tag:deprecated)" |
| 287 | +# Selects models with finance tag that don't have deprecated tag |
| 288 | + |
| 289 | +❯ sqlmesh plan dev --select-model "(+model_a | model_b+)" |
| 290 | +# Selects model_a and its upstream deps OR model_b and its downstream deps |
| 291 | + |
| 292 | +❯ sqlmesh plan dev --select-model "(tag:finance & git:main)" |
| 293 | +# Selects changed models that also have the finance tag |
| 294 | + |
| 295 | +❯ sqlmesh plan dev --select-model "^(tag:test) & metrics.*" |
| 296 | +# Selects models in metrics schema that don't have the test tag |
| 297 | +``` |
| 298 | + |
224 | 299 | ### Backfill examples
|
225 | 300 |
|
226 | 301 | #### No backfill selection
|
|
0 commit comments