You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guides/model_selection.md
+75Lines changed: 75 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -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
1. Show the models returnes by the selector that exist in both environments, but have no differences
139
-
2. Compare the models that have differences and display the table diff of each model
140
-
141
-
The `--select-model` option supports a powerful selection syntax that lets you choose models using patterns, tags, dependencies and git status. For complete details, see the [model selection guide](./model_selection.md).
138
+
1. Show the models returned by the selector that exist in both environments, but have no differences
139
+
2. Compare the models that have differences and display the data diff of each model
142
140
143
141
> Note: Models will only be data diffed if there's a breaking change that impacts them.
144
142
145
-
Here are some common patterns you can use:
143
+
The `--select-model` option supports a powerful selection syntax that lets you choose models using patterns, tags, dependencies and git status. For complete details, see the [model selection guide](./model_selection.md).
146
144
147
145
> Note: Surround your selection pattern in single or double quotes. Ex: `'*'`, `"sqlmesh_example.*"`
148
146
149
-
### Wildcard Patterns
150
-
151
-
-`*` - All models in the project
152
-
-`sqlmesh_example.*` - All models in the sqlmesh_example schema
153
-
154
-
### Upstream/Downstream Selection
155
-
156
-
-`+model_name` - Select the model and its upstream dependencies
157
-
-`model_name+` - Select the model and its downstream dependencies
158
-
-`+model_name+` - Select the model and both its upstream and downstream dependencies
159
-
160
-
### Tag-based Selection
161
-
162
-
-`tag:finance` - All models with the "finance" tag
163
-
-`tag:reporting*` - All models with tags starting with "reporting"
147
+
Here are some common examples:
164
148
165
-
### Git-based Selection
166
-
167
-
-`git:feature` - Select models whose files have changed compared to main branch, including:
168
-
- Untracked files (new files not in git)
169
-
- Uncommitted changes in working directory
170
-
- Committed changes different from main branch
171
-
-`+git:feature` - Select changed models and their upstream dependencies
172
-
-`git:feature+` - Select changed models and their downstream dependencies
173
-
174
-
> Note: Git-based selection excludes deleted files and respects your `.gitignore` settings.
175
-
176
-
### Logical Operators
177
-
178
-
You can combine multiple selectors using logical operators:
When multiple selectors are provided, they are combined with OR logic, meaning a model matching any of the selectors will be included.
199
171
200
-
All the standard table diff options like `--show-sample` work with multiple model diffing. The comparisons are executed concurrently for better performance when dealing with a large project or many models.
201
-
202
172
> Note: All models being compared must have their `grain` defined that is unique and not null, as this is used to perform the join between the tables in the two environments.
0 commit comments