Skip to content

Commit

Permalink
Merge branch 'add-node-selection' of github.com:dbt-labs/docs.getdbt.…
Browse files Browse the repository at this point in the history
…com into add-node-selection
  • Loading branch information
mirnawong1 committed Dec 13, 2024
2 parents 3ae512c + 725cf73 commit 6ab1863
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 19 deletions.
1 change: 1 addition & 0 deletions website/docs/docs/deploy/retry-jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ If your dbt job run completed with a status of **Error**, you can rerun it from

- You have a [dbt Cloud account](https://www.getdbt.com/signup).
- You must be using [dbt version](/docs/dbt-versions/upgrade-dbt-version-in-cloud) 1.6 or newer.
- dbt can successfully parse the project and generate a [manifest](/reference/artifacts/manifest-json)
- The most recent run of the job hasn't completed successfully. The latest status of the run is **Error**.
- The job command that failed in the run must be one that supports the [retry command](/reference/commands/retry).

Expand Down
11 changes: 6 additions & 5 deletions website/docs/reference/node-selection/defer.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ dbt test --models [...] --defer --state path/to/artifacts

</VersionBlock>

When the `--defer` flag is provided, dbt will resolve `ref` calls differently depending on two criteria:
1. Is the referenced node included in the model selection criteria of the current run?
2. Does the referenced node exist as a database object in the current environment?
By default, dbt uses the [`target`](/reference/dbt-jinja-functions/target) namespace to resolve `ref` calls.

If the answer to both is **no**—a node is not included _and_ it does not exist as a database object in the current environment—references to it will use the other namespace instead, provided by the state manifest.
When `--defer` is enabled, dbt resolves ref calls using the state manifest instead, but only if:

1. The node isn’t among the selected nodes, _and_
2. It doesn’t exist in the database (or `--favor-state` is used).

Ephemeral models are never deferred, since they serve as "passthroughs" for other `ref` calls.

Expand All @@ -46,7 +47,7 @@ Deferral requires both `--defer` and `--state` to be set, either by passing flag

#### Favor state

You can optionally skip the second criterion by passing the `--favor-state` flag. If passed, dbt will favor using the node defined in your `--state` namespace, even if the node exists in the current target.
When `--favor-state` is passed, dbt prioritizes node definitions from the `--state directory`. However, this doesn’t apply if the node is also part of the selected nodes.

### Example

Expand Down
117 changes: 103 additions & 14 deletions website/docs/reference/resource-configs/alias.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ datatype: string
<Tabs>
<TabItem value="model" label="Models">

Specify a custom alias for a model in your `dbt_project.yml` file or config block.
Specify a custom alias for a model in your `dbt_project.yml` file, `models/properties.yml` file, or config block in a SQL file.

For example, if you have a model that calculates `sales_total` and want to give it a more user-friendly alias, you can alias it like this:
For example, if you have a model that calculates `sales_total` and want to give it a more user-friendly alias, you can alias it as shown in the following examples.

In the `dbt_project.yml` file, the following example sets a default `alias` for the `sales_total` model at the project level:

<File name='dbt_project.yml'>

Expand All @@ -22,16 +24,40 @@ models:
```
</File>
The following specifies an `alias` as part of the `models/properties.yml` file metadata, useful for centralized configuration:

<File name='models/properties.yml'>

```yml
version: 2
models:
- name: sales_total
config:
alias: sales_dashboard
```
</File>

The following assigns the `alias` directly in the In `models/sales_total.sql` file:

<File name='models/sales_total.sql'>

```sql
{{ config(
alias="sales_dashboard"
) }}
```
</File>

This would return `analytics.finance.sales_dashboard` in the database, instead of the default `analytics.finance.sales_total`.

</TabItem>

<TabItem value="seeds" label="Seeds">

Configure a seed's alias in your `dbt_project.yml` file or a `properties.yml` file. The following examples demonstrate how to `alias` a seed named `product_categories` to `categories_data`.

Configure a seed's alias in your `dbt_project.yml` file or config block.

For example, if you have a seed that represents `product_categories` and want to alias it as `categories_data`, you would alias like this:
In the `dbt_project.yml` file at the project level:

<File name='dbt_project.yml'>

Expand All @@ -41,6 +67,21 @@ seeds:
product_categories:
+alias: categories_data
```
</File>

In the `seeds/properties.yml` file:

<File name='seeds/properties.yml'>

```yml
version: 2
seeds:
- name: product_categories
config:
alias: categories_data
```
</File>

This would return the name `analytics.finance.categories_data` in the database.

Expand All @@ -55,17 +96,16 @@ seeds:
+alias: country_mappings
```

</File>

</File>
</TabItem>

<TabItem value="snapshot" label="Snapshots">

Configure a snapshots's alias in your `dbt_project.yml` file or config block.

For example, if you have a snapshot that is named `your_snapshot` and want to alias it as `the_best_snapshot`, you would alias like this:
The following examples demonstrate how to `alias` a snapshot named `your_snapshot` to `the_best_snapshot`.

In the `dbt_project.yml` file at the project level:

<File name='dbt_project.yml'>

Expand All @@ -75,20 +115,57 @@ snapshots:
your_snapshot:
+alias: the_best_snapshot
```
</File>

This would build your snapshot to `analytics.finance.the_best_snapshot` in the database.
In the `snapshots/properties.yml` file:

<File name='snapshots/properties.yml'>

```yml
version: 2
snapshots:
- name: your_snapshot
config:
alias: the_best_snapshot
```
</File>

In `snapshots/your_snapshot.sql` file:

<File name='snapshots/your_snapshot.sql'>

```sql
{{ config(
alias="the_best_snapshot"
) }}
```
</File>

This would build your snapshot to `analytics.finance.the_best_snapshot` in the database.

</TabItem>

<TabItem value="test" label="Tests">

Configure a test's alias in your `schema.yml` file or config block.
Configure a data test's alias in your `dbt_project.yml` file, `properties.yml` file, or config block in the model file.

For example, to add a unique test to the `order_id` column and give it an alias `unique_order_id_test` to identify this specific test, you would alias like this:
The following examples demonstrate how to `alias` a unique data test named `order_id` to `unique_order_id_test` to identify a specific data test.

<File name='schema.yml'>
In the `dbt_project.yml` file at the project level:

<File name='dbt_project.yml'>

```yml
tests:
your_project:
+alias: unique_order_id_test
```
</File>

In the `models/properties.yml` file:

<File name='models/properties.yml'>

```yml
models:
Expand All @@ -99,10 +176,22 @@ models:
- unique:
alias: unique_order_id_test
```
</File>

In `tests/unique_order_id_test.sql` file:

<File name='tests/unique_order_id_test.sql'>

```sql
{{ config(
alias="unique_order_id_test",
severity="error",
```
</File>

When using [`store_failures_as`](/reference/resource-configs/store_failures_as), this would return the name `analytics.finance.orders_order_id_unique_order_id_test` in the database.

</File>

</TabItem>
</Tabs>

Expand Down

0 comments on commit 6ab1863

Please sign in to comment.