Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New empty mode for indirect selection #3738

Merged
merged 52 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
af1bad2
New empty mode for indirect selection
nghi-ly Jul 13, 2023
6530b57
This branch was auto-updated!
github-actions[bot] Jul 13, 2023
8be5806
This branch was auto-updated!
github-actions[bot] Jul 13, 2023
f34fde8
This branch was auto-updated!
github-actions[bot] Jul 13, 2023
33bf29c
This branch was auto-updated!
github-actions[bot] Jul 14, 2023
c1a0bdd
This branch was auto-updated!
github-actions[bot] Jul 14, 2023
b7baa3e
This branch was auto-updated!
github-actions[bot] Jul 14, 2023
645ae94
This branch was auto-updated!
github-actions[bot] Jul 14, 2023
f28778e
This branch was auto-updated!
github-actions[bot] Jul 14, 2023
a152d0f
This branch was auto-updated!
github-actions[bot] Jul 14, 2023
dab454d
This branch was auto-updated!
github-actions[bot] Jul 14, 2023
e433e48
This branch was auto-updated!
github-actions[bot] Jul 15, 2023
204bd81
This branch was auto-updated!
github-actions[bot] Jul 15, 2023
919a44a
This branch was auto-updated!
github-actions[bot] Jul 17, 2023
384b4e8
This branch was auto-updated!
github-actions[bot] Jul 17, 2023
1699a73
This branch was auto-updated!
github-actions[bot] Jul 17, 2023
1ff9e2e
This branch was auto-updated!
github-actions[bot] Jul 18, 2023
688595c
This branch was auto-updated!
github-actions[bot] Jul 18, 2023
7793880
This branch was auto-updated!
github-actions[bot] Jul 18, 2023
0034788
This branch was auto-updated!
github-actions[bot] Jul 18, 2023
7178c1d
This branch was auto-updated!
github-actions[bot] Jul 18, 2023
6a9cbec
This branch was auto-updated!
github-actions[bot] Jul 18, 2023
cff4749
This branch was auto-updated!
github-actions[bot] Jul 18, 2023
47dc394
This branch was auto-updated!
github-actions[bot] Jul 18, 2023
94de667
This branch was auto-updated!
github-actions[bot] Jul 19, 2023
698c6e1
This branch was auto-updated!
github-actions[bot] Jul 19, 2023
b2b7d84
This branch was auto-updated!
github-actions[bot] Jul 19, 2023
26b860f
This branch was auto-updated!
github-actions[bot] Jul 19, 2023
00bd6f4
This branch was auto-updated!
github-actions[bot] Jul 19, 2023
ce2ffbf
This branch was auto-updated!
github-actions[bot] Jul 19, 2023
faeb86e
This branch was auto-updated!
github-actions[bot] Jul 19, 2023
1dc1f37
This branch was auto-updated!
github-actions[bot] Jul 20, 2023
88c371f
This branch was auto-updated!
github-actions[bot] Jul 20, 2023
0ab28fc
This branch was auto-updated!
github-actions[bot] Jul 20, 2023
a8d145a
This branch was auto-updated!
github-actions[bot] Jul 20, 2023
a1e310f
This branch was auto-updated!
github-actions[bot] Jul 20, 2023
54f4725
This branch was auto-updated!
github-actions[bot] Jul 21, 2023
1d3d4e2
This branch was auto-updated!
github-actions[bot] Jul 21, 2023
b6f243f
This branch was auto-updated!
github-actions[bot] Jul 21, 2023
9ed6487
This branch was auto-updated!
github-actions[bot] Jul 21, 2023
c33da25
This branch was auto-updated!
github-actions[bot] Jul 21, 2023
ce10029
This branch was auto-updated!
github-actions[bot] Jul 21, 2023
143d42f
This branch was auto-updated!
github-actions[bot] Jul 23, 2023
4c75565
This branch was auto-updated!
github-actions[bot] Jul 24, 2023
ea8a9a8
This branch was auto-updated!
github-actions[bot] Jul 24, 2023
72665d9
This branch was auto-updated!
github-actions[bot] Jul 24, 2023
5f6b78c
This branch was auto-updated!
github-actions[bot] Jul 24, 2023
f597255
This branch was auto-updated!
github-actions[bot] Jul 24, 2023
bcef74c
This branch was auto-updated!
github-actions[bot] Jul 24, 2023
06daa73
This branch was auto-updated!
github-actions[bot] Jul 25, 2023
4774f5d
This branch was auto-updated!
github-actions[bot] Jul 25, 2023
cd70b4e
This branch was auto-updated!
github-actions[bot] Jul 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The "cautious" mode can be useful in environments when you're only building a su

</VersionBlock>

<VersionBlock firstVersion="1.4">
<VersionBlock firstVersion="1.4" lastVersion="1.4">

There are three modes to configure the behavior when performing indirect selection (with `eager` as the default):

Expand All @@ -72,6 +72,21 @@ The "buildable" and "cautious" modes can be useful in environments when you're o

</VersionBlock>

<VersionBlock firstVersion="1.5" >

There are three modes to configure the behavior when performing indirect selection (with `eager` as the default):

1. `eager` (default) - include ANY test that references the selected nodes
1. `cautious` - restrict to tests that ONLY refer to selected nodes
1. `buildable` - restrict to tests that ONLY refer to selected nodes (or their ancestors)
1. `empty` - restrict to tests that are only for the selected node and ignore all tests from the attached nodes
Copy link
Contributor Author

@nghi-ly nghi-ly Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Note that test exclusion is always greedy: if ANY parent is explicitly excluded, the test will be excluded as well.

The "buildable", "cautious", and "empty" modes can be useful in environments when you're only building a subset of your DAG, and you want to avoid test failures in "eager" mode caused by unbuilt resources. (Another way to achieve this is with [deferral](/reference/node-selection/defer)).

</VersionBlock>

<!--tabs for eager mode, cautious mode, and buildable mode -->

<VersionBlock lastVersion="1.3">
Expand Down Expand Up @@ -109,7 +124,57 @@ $ dbt build --select orders --indirect-selection=cautious

</VersionBlock>

<VersionBlock firstVersion="1.4">
<VersionBlock firstVersion="1.4" lastVersion="1.4">

<Tabs queryString="indirect-selection-mode">
<TabItem value="eager" label="Eager mode (default)">

By default, a test will run when ANY parent is selected; we call this "eager" indirect selection. In this example, that would include any test that references orders, even if it references other models as well.

In this mode, any test that depends on unbuilt resources will raise an error.

```shell
$ dbt test --select orders
$ dbt build --select orders
```

</TabItem>

<TabItem value="cautious" label="Cautious mode">

It is possible to prevent tests from running if one or more of its parents is unselected (and therefore unbuilt); we call this "cautious" indirect selection.

It will only include tests whose references are each within the selected nodes.

Put another way, it will prevent tests from running if one or more of its parents is unselected.

```shell
$ dbt test --select orders --indirect-selection=cautious
$ dbt build --select orders --indirect-selection=cautious
```

</TabItem>

<TabItem value="buildable" label="Buildable mode">

This mode is similarly conservative like "cautious", but is slightly more inclusive.

It will only include tests whose references are each within the selected nodes (or their ancestors).

This is useful in the same scenarios as "cautious", but also includes when a test depends on a model **and** a direct ancestor of that model (like confirming an aggregation has the same totals as its input).

```shell
$ dbt test --select orders --indirect-selection=buildable
$ dbt build --select orders --indirect-selection=buildable
```

</TabItem>

</Tabs>

</VersionBlock>

<VersionBlock firstVersion="1.5">

<Tabs queryString="indirect-selection-mode">
<TabItem value="eager" label="Eager mode (default)">
Expand Down Expand Up @@ -155,11 +220,22 @@ $ dbt build --select orders --indirect-selection=buildable

</TabItem>

<TabItem value="empty" label="Empty mode">

This mode will only include tests whose references are each within the selected nodes and will ignore all tests from attached nodes.

```shell
$ dbt test --select orders --indirect-selection=empty
$ dbt build --select orders --indirect-selection=empty
```

</TabItem>

</Tabs>

</VersionBlock>

<!--End of tabs for eager mode, cautious mode, and buildable mode -->
<!--End of tabs for eager mode, cautious mode, buildable mode, and empty mode -->

### Syntax examples

Expand Down
54 changes: 51 additions & 3 deletions website/docs/reference/node-selection/yaml-selectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ definition:

</VersionBlock>

<VersionBlock firstVersion="1.4">
<VersionBlock firstVersion="1.4" lastVersion="1.4">

```yml
definition:
Expand All @@ -95,7 +95,29 @@ definition:

childrens_parents: true | false # @ operator

indirect_selection: eager | cautious | buildable # include all tests selected indirectly? eager by default
indirect_selection: eager | cautious | buildable # include all tests selected indirectly? eager by default
```

</VersionBlock>

<VersionBlock firstVersion="1.5">

```yml
definition:
method: tag
value: nightly

# Optional keywords map to the `+` and `@` graph operators:

children: true | false
parents: true | false

children_depth: 1 # if children: true, degrees to include
parents_depth: 1 # if parents: true, degrees to include

childrens_parents: true | false # @ operator

indirect_selection: eager | cautious | buildable | empty # include all tests selected indirectly? eager by default
```

</VersionBlock>
Expand Down Expand Up @@ -168,7 +190,7 @@ If provided, a YAML selector's `indirect_selection` value will take precedence o

</VersionBlock>

<VersionBlock firstVersion="1.4">
<VersionBlock firstVersion="1.4" lastVersion="1.4">

As a general rule, dbt will indirectly select _all_ tests if they touch _any_ resource that you're selecting directly. We call this "eager" indirect selection. You can optionally switch the indirect selection mode to "cautious" or "buildable" by setting `indirect_selection` for a specific criterion:

Expand All @@ -191,6 +213,32 @@ If provided, a YAML selector's `indirect_selection` value will take precedence o

</VersionBlock>

<VersionBlock firstVersion="1.5">

As a general rule, dbt will indirectly select _all_ tests if they touch _any_ resource that you're selecting directly. We call this "eager" indirect selection. You can optionally switch the indirect selection mode to "cautious", "buildable", or "empty" by setting `indirect_selection` for a specific criterion:

```yml
- union:
- method: fqn
value: model_a
indirect_selection: eager # default: will include all tests that touch model_a
- method: fqn
value: model_b
indirect_selection: cautious # will not include tests touching model_b
# if they have other unselected parents
- method: fqn
value: model_c
indirect_selection: buildable # will not include tests touching model_c
# if they have other unselected parents (unless they have an ancestor that is selected)
- method: fqn
value: model_d
indirect_selection: empty # will include tests for only the selected node and ignore all tests attached to model_d
```

If provided, a YAML selector's `indirect_selection` value will take precedence over the CLI flag `--indirect-selection`. Because `indirect_selection` is defined separately for _each_ selection criterion, it's possible to mix eager/cautious/buildable/empty modes within the same definition, to achieve the exact behavior that you need. Remember that you can always test out your critiera with `dbt ls --selector`.

</VersionBlock>

See [test selection examples](/reference/node-selection/test-selection-examples) for more details about indirect selection.

## Example
Expand Down