Skip to content

Commit cd13928

Browse files
revise docs
1 parent 50dfcc3 commit cd13928

3 files changed

Lines changed: 93 additions & 48 deletions

File tree

docs/guides/model_selection.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,81 @@ Models:
221221
└── sushi.customer_revenue_lifetime
222222
```
223223

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+
224299
### Backfill examples
225300

226301
#### No backfill selection

docs/guides/tablediff.md

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -135,70 +135,40 @@ sqlmesh table_diff prod:dev --select-model "sqlmesh_example.*"
135135

136136
When diffing multiple models, SQLMesh will:
137137

138-
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
142140

143141
> Note: Models will only be data diffed if there's a breaking change that impacts them.
144142
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).
146144

147145
> Note: Surround your selection pattern in single or double quotes. Ex: `'*'`, `"sqlmesh_example.*"`
148146
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:
164148

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:
179-
- `&` (AND): Both conditions must be true
180-
- `|` (OR): Either condition must be true
181-
- `^` (NOT): Negates a condition
149+
```bash
150+
# Select all models in a schema
151+
sqlmesh table_diff prod:dev -m "sqlmesh_example.*"
182152

183-
#### Complex Selection Examples
153+
# Select a model and its dependencies
154+
sqlmesh table_diff prod:dev -m "+model_name" # include upstream deps
155+
sqlmesh table_diff prod:dev -m "model_name+" # include downstream deps
184156

185-
- `(tag:finance & ^tag:deprecated)` - Models with finance tag that don't have deprecated tag
186-
- `(+model_a | model_b+)` - Model A and its upstream deps OR model B and its downstream deps
187-
- `(tag:finance & git:main)` - Changed models that also have the finance tag
188-
- `^(tag:test) & metrics.*` - Models in metrics schema that don't have the test tag
157+
# Select models by tag
158+
sqlmesh table_diff prod:dev -m "tag:finance"
189159

190-
### Multiple selectors
160+
# Select models with git changes
161+
sqlmesh table_diff prod:dev -m "git:feature"
191162

192-
You can also combine multiple selectors in a single command:
163+
# Use logical operators for complex selections
164+
sqlmesh table_diff prod:dev -m "(metrics.* & ^tag:deprecated)" # finance models that aren't deprecated
193165

194-
```bash
166+
# Combine multiple selectors
195167
sqlmesh table_diff prod:dev -m "tag:finance" -m "metrics.*_daily"
196168
```
197169

198170
When multiple selectors are provided, they are combined with OR logic, meaning a model matching any of the selectors will be included.
199171

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-
202172
> 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.
203173
204174
## Diffing tables or views

sqlmesh/core/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ def table_diff(
15881588
on: The join condition, table aliases must be "s" and "t" for source and target.
15891589
If omitted, the table's grain will be used.
15901590
skip_columns: The columns to skip when computing the table diff.
1591-
select_models: The modelσ or snapshotσ to use when environments are passed in.
1591+
select_models: The models or snapshots to use when environments are passed in.
15921592
where: An optional where statement to filter results.
15931593
limit: The limit of the sample dataframe.
15941594
show: Show the table diff output in the console.

0 commit comments

Comments
 (0)