Skip to content

Commit

Permalink
add section to explain select and selector (#6800)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirnawong1 authored Jan 22, 2025
2 parents 8798f46 + 50493a9 commit caeae60
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions website/docs/reference/node-selection/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Selector methods return all resources that share a common property, using the
syntax `method:value`. While it is recommended to explicitly denote the method,
you can omit it (the default value will be one of `path`, `file` or `fqn`).

<Expandable alt_header="Differences between --select and --selector">

The `--select` and `--selector` arguments sound similar, but they are different. To understand the difference, see [Differences between `--select` and `--selector`](/reference/node-selection/yaml-selectors#difference-between---select-and---selector).

</Expandable>

Many of the methods below support Unix-style wildcards:

Expand Down
4 changes: 4 additions & 0 deletions website/docs/reference/node-selection/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ dbt's node selection syntax makes it possible to run only specific resources in
We use the terms <a href="https://en.wikipedia.org/wiki/Vertex_(graph_theory)">"nodes"</a> and "resources" interchangeably. These encompass all the models, tests, sources, seeds, snapshots, exposures, and analyses in your project. They are the objects that make up dbt's DAG (directed acyclic graph).
:::

The `--select` and `--selector` arguments are similar in that they both allow you to select resources. To understand the difference, see [Differences between `--select` and `--selector`](/reference/node-selection/yaml-selectors#difference-between---select-and---selector).

## Specifying resources

By default, `dbt run` executes _all_ of the models in the dependency graph; `dbt seed` creates all seeds, `dbt snapshot` performs every snapshot. The `--select` flag is used to specify a subset of nodes to execute.
Expand Down Expand Up @@ -103,6 +105,8 @@ As your selection logic gets more complex, and becomes unwieldly to type out as
consider using a [yaml selector](/reference/node-selection/yaml-selectors). You can use a predefined definition with the `--selector` flag.
Note that when you're using `--selector`, most other flags (namely `--select` and `--exclude`) will be ignored.

The `--select` and `--selector` arguments are similar in that they both allow you to select resources. To understand the difference between `--select` and `--selector` arguments, see [this section](/reference/node-selection/yaml-selectors#difference-between---select-and---selector) for more details.

### Troubleshoot with the `ls` command

Constructing and debugging your selection syntax can be challenging. To get a "preview" of what will be selected, we recommend using the [`list` command](/reference/commands/list). This command, when combined with your selection syntax, will output a list of the nodes that meet that selection criteria. The `dbt ls` command supports all types of selection syntax arguments, for example:
Expand Down
19 changes: 19 additions & 0 deletions website/docs/reference/node-selection/yaml-selectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,22 @@ selectors:
**Note:** While selector inheritance allows the logic from another selector to be _reused_, it doesn't allow the logic from that selector to be _modified_ by means of `parents`, `children`, `indirect_selection`, and so on.

The `selector` method returns the complete set of nodes returned by the named selector.

## Difference between `--select` and `--selector`

In dbt, [`select`](/reference/node-selection/syntax#how-does-selection-work) and `selector` are related concepts used for choosing specific models, tests, or resources. The following tables explains the differences and when to best use them:

| Feature | `--select` | `--selector` |
| ------- | ---------- | ------------- |
| Definition | Ad-hoc, specified directly in the command. | Pre-defined in `selectors.yml` file. |
| Usage | One-time or task-specific filtering.| Reusable for multiple executions. |
| Complexity | Requires manual entry of selection criteria. | Can encapsulate complex logic for reuse. |
| Flexibility | Flexible; less reusable. | Flexible; focuses on reusable and structured logic.|
| Example | `dbt run --select my_model+`<br /> (runs `my_model` and all downstream dependencies with the `+` operator). | `dbt run --selector nightly_diet_snowplow`<br /> (runs models defined by the `nightly_diet_snowplow` selector in `selectors.yml`). |

Notes:
- You can combine `--select` with `--exclude` for ad-hoc selection of nodes.
- The `--select` and `--selector` syntax both provide the same overall functions for node selection. Using [graph operators](/reference/node-selection/graph-operators) (such as `+`, `@`.) and [set operators](/reference/node-selection/set-operators) (such as `union` and `intersection`) in `--select` is the same as YAML-based configs in `--selector`.


For additional examples, check out [this GitHub Gist](https://gist.github.com/jeremyyeo/1aeca767e2a4f157b07955d58f8078f7).

0 comments on commit caeae60

Please sign in to comment.