Skip to content

Commit 5f9273b

Browse files
committed
Source freshness
1 parent 5af27ee commit 5f9273b

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

website/docs/docs/build/sources.md

+8
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ The results of this query are used to determine whether the source is fresh or n
191191

192192
<Lightbox src="/img/docs/building-a-dbt-project/snapshot-freshness.png" title="Uh oh! Not everything is as fresh as we'd like!"/>
193193

194+
### Build models based on source freshness
195+
196+
dbt has a feature to [check the freshness](https://docs.getdbt.com/docs/build/sources#declaring-source-freshness) (how up to date) of a specific source. This functionality is specifically designed for sources and does not apply to models.
197+
198+
Neither `dbt source freshness` nor `dbt test` will perform any freshness checking of models. This is intentional because, in a typical dbt project, raw data usually comes in as sources. Your models then transform this data by selecting from those sources. If your source data is fresh, there's generally no need to perform freshness checks on your models as well.
199+
200+
However, dbt does however does provide the flexibility for users to create their own [generic tests](https://docs.getdbt.com/docs/build/tests#generic-tests) that they can then apply to models.
201+
194202
### Filter
195203

196204
Some databases can have tables where a filter over certain columns are required, in order prevent a full scan of the table, which could be costly. In order to do a freshness check on such tables a `filter` argument can be added to the configuration, e.g. `filter: _etl_loaded_at >= date_sub(current_date(), interval 1 day)`. For the example above, the resulting query would look like

website/docs/reference/commands/source.md

+22
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ The `dbt source` command provides subcommands that are useful when working with
1212

1313
If your dbt project is [configured with sources](/docs/build/sources), then the `dbt source freshness` command will query all of your defined source tables, determining the "freshness" of these tables. If the tables are stale (based on the `freshness` config specified for your sources) then dbt will report a warning or error accordingly. If a source <Term id="table" /> is in a stale state, then dbt will exit with a nonzero exit code.
1414

15+
You can also use [source freshness](/docs/deploy/source-freshness) commands help make sure the data you get is new and not old or outdated.
16+
17+
#### Configure source freshness
18+
19+
You can configure source freshness in the execution settings within your job in dbt Cloud. For more information, refer to [enabling source freshness snapshots](/docs/deploy/source-freshness#enabling-source-freshness-snapshots).
20+
21+
import SourcefreshnessTable from '/snippets/_selecting_source_freshness.md';
22+
23+
<SourcefreshnessTable />
24+
1525
### Specifying sources to snapshot
1626

1727
By default, `dbt source freshness` will calculate freshness information for all of the sources in your project. To snapshot freshness for a subset of these sources, use the `--select` flag.
@@ -76,3 +86,15 @@ Snapshots of source freshness can be used to understand:
7686
This command can be run manually to determine the state of your source data freshness at any time. It is also recommended that you run this command on a schedule, storing the results of the freshness snapshot at regular intervals. These longitudinal snapshots will make it possible to be alerted when source data freshness SLAs are violated, as well as understand the trend of freshness over time.
7787

7888
dbt Cloud makes it easy to snapshot source freshness on a schedule, and provides a dashboard out of the box indicating the state of freshness for all of the sources defined in your project. For more information on snapshotting freshness in dbt Cloud, check out the [docs](/docs/build/sources#source-data-freshness).
89+
90+
### Source freshness commands
91+
92+
Source freshness commands ensure you're receiving the most up-to-date, relevant, and accurate information.
93+
94+
Some of the typical commands you can use are:
95+
96+
| **Command** | **Description** |
97+
| ----------------------------------------------------------------------------| ---------------------------------|
98+
|[`source_status`](/reference/node-selection/methods#the-source_status-method)|dbt generates the [`sources.json`](/reference/artifacts/sources-json) artifact, which includes execution times and [`max_loaded_at`](/reference/artifacts/sources-json#top-level-keys) timestamps for dbt sources.|
99+
|[`state:modified`](/reference/node-selection/methods#state) |Used to select nodes by comparing them to a previous version of the same project, represented by a [manifest](/reference/artifacts/manifest-json).|
100+
|[`dbt source freshness`](/reference/commands/source#dbt-source-freshness) |If your dbt project includes configured sources, the dbt source freshness command will query all your defined source tables to determine their "freshness."|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<Lightbox src="/img/docs/dbt-cloud/select-source-freshness.png" title="Selecting source freshness"/>

0 commit comments

Comments
 (0)