-
Notifications
You must be signed in to change notification settings - Fork 969
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New
snapshot_meta_column_names
config for dbt snapshots (#6211)
Resolves #6112 ## What are you changing in this pull request and why? In Versionless and dbt v1.9, we have a new `snapshot_meta_column_names` config for dbt snapshots that allows for customizing the [column names of the snapshot meta fields](https://docs.getdbt.com/docs/build/snapshots#snapshot-meta-fields) (`dbt_valid_from`, `dbt_valid_to`, `dbt_scd_id`, `dbt_updated_at`) to align with team or organizational conventions. For example, they can now have _whichever_ column names you choose (e.g., `valid_start`, `valid_end`, `scd_identifier`, `last_modified`). ## Previews - [`snapshot_meta_column_names`](https://docs-getdbt-com-git-dbeatty10-patch-1-dbt-labs.vercel.app/reference/resource-configs/snapshot_meta_column_names) - [Snapshot configurations](https://docs-getdbt-com-git-dbeatty10-patch-1-dbt-labs.vercel.app/reference/snapshot-configs#snapshot-specific-configurations) - [Snapshot meta-fields](https://docs-getdbt-com-git-dbeatty10-patch-1-dbt-labs.vercel.app/docs/build/snapshots#snapshot-meta-fields) - [dbt Cloud release notes](https://docs-getdbt-com-git-dbeatty10-patch-1-dbt-labs.vercel.app/docs/dbt-versions/dbt-cloud-release-notes#october-2024) ## Checklist - [x] I have reviewed the [Content style guide](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/content-style-guide.md) so my content adheres to these guidelines. - [x] The topic I'm writing about is for specific dbt version(s) and I have versioned it according to the [version a whole page](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/single-sourcing-content.md#adding-a-new-version) and/or [version a block of content](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/single-sourcing-content.md#versioning-blocks-of-content) guidelines. - [x] Add a note to the [release notes](https://github.com/dbt-labs/docs.getdbt.com/tree/current/website/docs/docs/dbt-versions/release-notes.md) - [ ] Add a note to the prerelease version [Migration Guide](https://github.com/dbt-labs/docs.getdbt.com/tree/current/website/docs/docs/dbt-versions/core-upgrade) - [x] Add page in `website/sidebars.js` - [x] Provide a unique filename for new pages --------- Co-authored-by: Mirna Wong <[email protected]> Co-authored-by: Leona B. Campbell <[email protected]> Co-authored-by: Grace Goheen <[email protected]>
- Loading branch information
1 parent
c8b4993
commit f90259f
Showing
6 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
website/docs/reference/resource-configs/snapshot_meta_column_names.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
--- | ||
resource_types: [snapshots] | ||
description: "Snapshot meta column names" | ||
datatype: "{<dictionary>}" | ||
default_value: {"dbt_valid_from": "dbt_valid_from", "dbt_valid_to": "dbt_valid_to", "dbt_scd_id": "dbt_scd_id", "dbt_updated_at": "dbt_updated_at"} | ||
id: "snapshot_meta_column_names" | ||
--- | ||
|
||
Starting in 1.9 or with [versionless](/docs/dbt-versions/upgrade-dbt-version-in-cloud#versionless) dbt Cloud. | ||
|
||
<File name='snapshots/schema.yml'> | ||
|
||
```yaml | ||
snapshots: | ||
- name: <snapshot_name> | ||
config: | ||
snapshot_meta_column_names: | ||
dbt_valid_from: <string> | ||
dbt_valid_to: <string> | ||
dbt_scd_id: <string> | ||
dbt_updated_at: <string> | ||
|
||
``` | ||
|
||
</File> | ||
|
||
<File name='snapshots/<filename>.sql'> | ||
|
||
```jinja2 | ||
{{ | ||
config( | ||
snapshot_meta_column_names={ | ||
"dbt_valid_from": "<string>", | ||
"dbt_valid_to": "<string>", | ||
"dbt_scd_id": "<string>", | ||
"dbt_updated_at": "<string>", | ||
} | ||
) | ||
}} | ||
``` | ||
|
||
</File> | ||
|
||
<File name='dbt_project.yml'> | ||
|
||
```yml | ||
snapshots: | ||
[<resource-path>](/reference/resource-configs/resource-path): | ||
+snapshot_meta_column_names: | ||
dbt_valid_from: <string> | ||
dbt_valid_to: <string> | ||
dbt_scd_id: <string> | ||
dbt_updated_at: <string> | ||
|
||
``` | ||
|
||
</File> | ||
|
||
## Description | ||
|
||
In order to align with an organization's naming conventions, the `snapshot_meta_column_names` config can be used to customize the names of the [metadata columns](/docs/build/snapshots#snapshot-meta-fields) within each snapshot. | ||
|
||
## Default | ||
|
||
By default, dbt snapshots use the following column names to track change history using [Type 2 slowly changing dimension](https://en.wikipedia.org/wiki/Slowly_changing_dimension#Type_2:_add_new_row) records: | ||
|
||
| Field | Meaning | Notes | | ||
| -------------- | ------- | ----- | | ||
| `dbt_valid_from` | The timestamp when this snapshot row was first inserted and became valid. | The value is affected by the [`strategy`](/reference/resource-configs/strategy). | | ||
| `dbt_valid_to` | The timestamp when this row is no longer valid. | | | ||
| `dbt_scd_id` | A unique key generated for each snapshot row. | This is used internally by dbt. | | ||
| `dbt_updated_at` | The `updated_at` timestamp of the source record when this snapshot row was inserted. | This is used internally by dbt. | | ||
|
||
However, these column names can be customized using the `snapshot_meta_column_names` config. | ||
|
||
:::warning | ||
|
||
To avoid any unintentional data modification, dbt will **not** automatically apply any column renames. So if a user applies `snapshot_meta_column_names` config for a snapshot without updating the pre-existing table, they will get an error. We recommend either only using these settings for net-new snapshots, or arranging an update of pre-existing tables prior to committing a column name change. | ||
|
||
::: | ||
|
||
## Example | ||
|
||
<File name='snapshots/schema.yml'> | ||
|
||
```yaml | ||
snapshots: | ||
- name: orders_snapshot | ||
relation: ref("orders") | ||
config: | ||
unique_key: id | ||
strategy: check | ||
check_cols: all | ||
snapshot_meta_column_names: | ||
dbt_valid_from: start_date | ||
dbt_valid_to: end_date | ||
dbt_scd_id: scd_id | ||
dbt_updated_at: modified_date | ||
``` | ||
</File> | ||
The resulting snapshot table contains the configured meta column names: | ||
| id | scd_id | modified_date | start_date | end_date | | ||
| -- | -------------------- | -------------------- | -------------------- | -------------------- | | ||
| 1 | 60a1f1dbdf899a4dd... | 2024-10-02 ... | 2024-10-02 ... | 2024-10-02 ... | | ||
| 2 | b1885d098f8bcff51... | 2024-10-02 ... | 2024-10-02 ... | | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters