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
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
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).
Copy file name to clipboardExpand all lines: docs/guides/tablediff.md
+71Lines changed: 71 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -122,6 +122,77 @@ Under the hood, SQLMesh stores temporary data in the database to perform the com
122
122
The default schema for these temporary tables is `sqlmesh_temp` but can be changed with the `--temp-schema` option.
123
123
The schema can be specified as a `CATALOG.SCHEMA` or `SCHEMA`.
124
124
125
+
126
+
## Diffing multiple models across environments
127
+
128
+
SQLMesh allows you to compare multiple models across environments at once using model selection expressions. This is useful when you want to validate changes across a set of related models or the entire project.
129
+
130
+
To diff multiple models, use the `--select-model` (or `-m` for short) option with the table diff command:
1. Show which models exist only in the source environment
139
+
2. Show which models exist only in the target environment
140
+
3. Show which models exist in both environments but have no differences
141
+
4. Compare the models that have differences and display them
142
+
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).
144
+
145
+
Here are some common patterns you can use:
146
+
147
+
### Wildcard Patterns
148
+
-`*` - All models in the project
149
+
-`sqlmesh_example.*` - All models in the sqlmesh_example schema
150
+
151
+
### Upstream/Downstream Selection
152
+
-`+model_name` - Select the model and its upstream dependencies
153
+
-`model_name+` - Select the model and its downstream dependencies
154
+
-`+model_name+` - Select the model and both its upstream and downstream dependencies
155
+
156
+
### Tag-based Selection
157
+
-`tag:finance` - All models with the "finance" tag
158
+
-`tag:reporting*` - All models with tags starting with "reporting"
159
+
160
+
### Git-based Selection
161
+
-`git:feature` - Select models whose files have changed compared to main branch, including:
162
+
- Untracked files (new files not in git)
163
+
- Uncommitted changes in working directory
164
+
- Committed changes different from main branch
165
+
-`+git:feature` - Select changed models and their upstream dependencies
166
+
-`git:feature+` - Select changed models and their downstream dependencies
167
+
168
+
> Note: Git-based selection excludes deleted files and respects your `.gitignore` settings.
169
+
170
+
### Logical Operators
171
+
You can combine multiple selectors using logical operators:
172
+
-`&` (AND): Both conditions must be true
173
+
-`|` (OR): Either condition must be true
174
+
-`^` (NOT): Negates a condition
175
+
176
+
#### Complex Selection Examples
177
+
-`(tag:finance & ^tag:deprecated)` - Models with finance tag that don't have deprecated tag
178
+
-`(+model_a | model_b+)` - Model A and its upstream deps OR model B and its downstream deps
179
+
-`(tag:finance & git:main)` - Changed models that also have the finance tag
180
+
-`^(tag:test) & metrics.*` - Models in metrics schema that don't have the test tag
181
+
182
+
### Multiple selectors
183
+
184
+
You can also combine multiple selectors in a single command:
When multiple selectors are provided, they are combined with OR logic, meaning a model matching any of the selectors will be included.
191
+
192
+
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 of project or many models.
193
+
194
+
> Note: All models being compared must have their `grain` defined, as this is used to perform the join between the tables in the two environments.
195
+
125
196
## Diffing tables or views
126
197
127
198
Compare specific tables or views with the SQLMesh CLI interface by using the command `sqlmesh table_diff [source table]:[target table]`.
help="Select specific model that should be diffed.",
900
+
help="Specify one or more models to data diff. Use wildcards to diff multiple models. Ex: '*' (all models with applied plan diffs), 'demo.model+' (this and downstream models), 'git:feature_branch' (models with direct modifications in this branch only)",
help="Select specific model changes that should be included in the plan.",
693
+
help="Specify one or more models to data diff. Use wildcards to diff multiple models. Ex: '*' (all models with applied plan diffs), 'demo.model+' (this and downstream models), 'git:feature_branch' (models with direct modifications in this branch only)",
0 commit comments