-
Notifications
You must be signed in to change notification settings - Fork 960
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
Initial "wireframe" for model contracts #2890
Merged
Merged
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8fa8192
dbt-constraints-docs (#2601)
sungchun12 33ccf31
Initialize v1.5
jtcohen6 79c4cfa
Initial skeleton drafts
jtcohen6 6fe3771
Write a bit more
jtcohen6 8411c75
Fix broken links
jtcohen6 38b0427
Update model-access.md
matthewshaver 32e3ebe
Update model-contracts.md
matthewshaver d52d1ff
Update model-versions.md
matthewshaver 33aebe3
Update model-contracts.md
matthewshaver 47ef10d
Update model-versions.md
matthewshaver 5531317
Update website/docs/reference/resource-configs/contract.md
matthewshaver 32b4ccd
Update website/docs/reference/resource-configs/contract.md
matthewshaver 5be6340
Update contract.md
matthewshaver 0ffec2a
Merge branch 'current' into jerco/model-contracts
matthewshaver 71b787b
Update website/docs/docs/collaborate/publish/model-contracts.md
matthewshaver 81b6330
Apply suggestions from code review
matthewshaver 23ee4ef
Apply suggestions from code review
matthewshaver 4eee716
Merge branch 'current' into jerco/model-contracts
dbeatty10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
title: "Model access" | ||
--- | ||
|
||
:::info Beta functionality | ||
This functionality is new in v1.5! These docs exist to provide a high-level overview of what's to come. Specific syntax is liable to change. | ||
|
||
For more details, and to leave your feedback, check out the GitHub discussion: | ||
* ["Model groups & access" (dbt-core#6730)](https://github.com/dbt-labs/dbt-core/discussions/6730) | ||
::: | ||
|
||
## Related documentation | ||
* TK: `groups` | ||
* TK: `access` modifiers | ||
|
||
### Groups | ||
|
||
Models can be grouped together under a common designation, with a shared owner. | ||
|
||
Why define model `groups`? | ||
- It turns implicit relationships into an explicit grouping | ||
- It enables you to mark certain models as "private," for use _only_ within that group | ||
|
||
### Access modifiers | ||
|
||
Some models (not all of them) are designed to be shared across groups. | ||
|
||
https://en.wikipedia.org/wiki/Access_modifiers | ||
|
||
| Keyword | Meaning | | ||
|-----------|----------------------| | ||
| private | same group | | ||
| protected | same project/package | | ||
| public | everybody* | | ||
|
||
By default, all models are "protected." This means that they can be referenced by other models in the same project. | ||
|
||
:::info Under construction 🚧 | ||
More to come! The syntax below is suggestive only, it does not yet work. | ||
::: | ||
|
||
<File name="models/marts/customers.yml"> | ||
|
||
```yaml | ||
groups: | ||
- name: cx | ||
owner: | ||
name: Customer Success Team | ||
email: cx@jaffle.shop | ||
|
||
models: | ||
- name: dim_customers | ||
group: cx | ||
access: public | ||
# this is an intermediate transformation -- relevant to the CX team only | ||
- name: int__customer_history_rollup | ||
group: cx | ||
access: private | ||
``` | ||
|
||
</File> |
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,86 @@ | ||
--- | ||
title: "Model contracts" | ||
--- | ||
|
||
:::info Beta functionality | ||
This functionality is new in v1.5! These docs exist to provide a high-level overview of what's to come. Specific syntax is liable to change. | ||
|
||
For more details, and to leave your feedback, check out the GitHub discussion: | ||
* ["Model contracts" (dbt-core#6726)](https://github.com/dbt-labs/dbt-core/discussions/6726) | ||
::: | ||
|
||
## Related documentation | ||
* [`contract`](resource-configs/contract) | ||
* [`columns`](resource-properties/columns) | ||
* [`constraints`](resource-properties/constraints) | ||
|
||
## Why define a contract? | ||
|
||
Defining a dbt model is as easy as writing a SQL `select` statement, or a Python Data Frame transformation. Your query naturally produces a dataset with columns of names and types, based on the columns you're selecting and the transformations you're applying. | ||
|
||
While this is great for quick & iterative development, for some models, constantly changing the shape of the model's returned dataset poses a risk, when there are other people and processes querying that model. It's better to define a set of **upfront guarantees** about the shape of your model. We call this set of guarantees a "contract." While building your model, dbt will verify that your model's transformation will produce a dataset matching up with its contract—or it will fail to build. | ||
|
||
## How to define a contract | ||
|
||
Let's say you have a model with a query like: | ||
|
||
<File name="models/marts/dim_customers.sql"> | ||
|
||
```sql | ||
-- lots of SQL | ||
|
||
final as ( | ||
|
||
select | ||
-- lots of columns | ||
from ... | ||
|
||
) | ||
|
||
select * from final | ||
``` | ||
</File> | ||
|
||
Your contract **must** include every column's `name` and `data_type` (where `data_type` matches the type understood by your data platform). If your model is being materialized as `table` or `incremental`, you may optionally specify that certain columns must be `not_null` (i.e. contain zero null values). Depending on your data platform, you may also be able to define additional `constraints` that are enforced while the model is being built. | ||
|
||
Finally, you configure your model with `contract: true`. | ||
|
||
<File name="models/marts/customers.yml"> | ||
|
||
```yaml | ||
models: | ||
- name: dim_customers | ||
config: | ||
contract: true | ||
columns: | ||
- name: customer_id | ||
data_type: int | ||
not_null: true | ||
- name: customer_name | ||
data_type: string | ||
... | ||
``` | ||
|
||
</File> | ||
|
||
When building a model with a defined contract, dbt will do two things differently: | ||
1. dbt will run a "pre-flight" check to ensure that the model's query will return a set of columns with names and data types matching the ones you have defined. | ||
2. dbt will pass the column names, types, `not_null` and other constraints into the DDL statements it submits to the data platform, where they will be enforced while building the table. | ||
|
||
## FAQs | ||
|
||
### Which models should have contracts? | ||
|
||
Any model can define a contract. It's especially important to define contracts for "public" models that are being shared with other groups, teams, and (soon) dbt projects. | ||
|
||
### How are contracts different from tests? | ||
|
||
A model's contract defines the **shape** of the returned dataset. | ||
|
||
[Tests](tests) are a more flexible mechanism for validating the content of your model. So long as you can write the query, you can run the test. Tests are also more configurable, via `severity` and custom thresholds, and easier to debug after finding failures, because the model has already built, and the relevant records can be materialized in the data warehouse by [storing failures](resource-configs/store_failures). | ||
|
||
In blue/green deployments (docs link TK), ... <!-- TODO write more here --> | ||
|
||
In the parallel for software APIs: | ||
- The structure of the API response is the contract | ||
- Quality and reliability ("uptime") are also **crucial**, but not part of the contract per se. |
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,28 @@ | ||
--- | ||
title: "Model versions" | ||
--- | ||
|
||
:::info Beta functionality | ||
This functionality is new in v1.5! These docs exist to provide a high-level overview of what's to come. Specific syntax is liable to change. | ||
|
||
For more details, and to leave your feedback, check out the GitHub discussion: | ||
* ["Model versions" (dbt-core#6736)](https://github.com/dbt-labs/dbt-core/discussions/6736) | ||
::: | ||
|
||
API versioning is **a hard problem** in software engineering. It's also very important. Our goal is to _make a hard thing possible_. | ||
|
||
## Related documentation | ||
* TK: `version` & `latest` (_not_ [this one](project-configs/version)) | ||
* TK: `deprecation_date` | ||
|
||
## Why version a model? | ||
|
||
If a model defines a ["contract"](model-contracts) (a set of guarantees for its structure), it's also possible to change that model's contract in a way that "breaks" the previous set of guarantees. | ||
|
||
One approach is to force every consumer of the model to immediately handle the breaking change, as soon as it's deployed to production. While this may work at smaller organizations, or while iterating on an immature set of data models, it doesn't scale much beyond that. | ||
|
||
Instead, the owner of the model can create a **new version**, and provide a **deprecation window**, during which consumers can migrate from the old version to the new. | ||
|
||
In the meantime, anywhere that model is used downstream, it can be referenced at a specific version. | ||
|
||
When a model is reaching its deprecation date, consumers of that model will hear about it. When the date is reached, it goes away. |
57 changes: 57 additions & 0 deletions
57
website/docs/guides/migration/versions/02-upgrading-to-v1.5.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,57 @@ | ||
--- | ||
title: "Trying v1.5 (prerelease)" | ||
description: New features and changes in dbt Core v1.5 | ||
--- | ||
|
||
:::info | ||
v1.5 is currently available as a **beta prerelease.** Availability in dbt Cloud coming soon! | ||
::: | ||
|
||
### Resources | ||
|
||
- [Changelog](https://github.com/dbt-labs/dbt-core/blob/main/CHANGELOG.md) | ||
- [CLI Installation guide](/docs/get-started/installation) | ||
- [Cloud upgrade guide](/docs/dbt-versions/upgrade-core-in-cloud) | ||
- [Release schedule](https://github.com/dbt-labs/dbt-core/issues/6715) | ||
|
||
**Planned final release:** April 26, 2023 | ||
|
||
dbt Core v1.5 is a feature release, with two big additions planned: | ||
1. **"Models as APIs,"** the first phase of [multi-project deployments](https://github.com/dbt-labs/dbt-core/discussions/6725) | ||
2. An initial **Python API for dbt-core,** supporting programmatic invocations at parity with the CLI | ||
|
||
## What to know before upgrading | ||
|
||
dbt Labs is committed to providing backward compatibility for all versions 1.x, with the exception of any changes explicitly mentioned below. If you encounter an error upon upgrading, please let us know by [opening an issue](https://github.com/dbt-labs/dbt-core/issues/new). | ||
|
||
### Breaking changes | ||
|
||
As part of our refactor of `dbt-core` internals, we need to make some **very precise** changes to runtime configuration. The net result of these changes is more sensible configuration options, clearer documentation, cleaner APIs, and a more legible codebase. | ||
|
||
Wherever possible, we will aim to provide backwards compatibility and deprecation warnings for at least one minor version, before actually removing the old functionality. In those cases, we still reserve the right to fully remove the backward-compatible functionality in a future v1.x minor version of `dbt-core`. | ||
|
||
Changes planned for v1.5: | ||
- Renaming ["global configs"](global-configs) for consistency ([dbt-core#6903](https://github.com/dbt-labs/dbt-core/issues/6903)) | ||
- Moving `log-path` and `target-path` out of `dbt_project.yml`, for consistency with other global configs ([dbt-core#6882](https://github.com/dbt-labs/dbt-core/issues/6882)) | ||
|
||
### For consumers of dbt artifacts (metadata) | ||
|
||
The manifest schema version will be updated to `v9`. Specific changes to be noted here. | ||
|
||
### For maintainers of adapter plugins | ||
|
||
Forthcoming: GH discussion detailing interface changes, and offering a forum for Q&A | ||
|
||
## New and changed documentation | ||
|
||
:::caution Under construction 🚧 | ||
More to come! | ||
::: | ||
|
||
### Publishing models as APIs | ||
- [Model contracts](model-contracts) ([#2839](https://github.com/dbt-labs/docs.getdbt.com/issues/2839)) | ||
- [Model access](model-access) ([#2840](https://github.com/dbt-labs/docs.getdbt.com/issues/2840)) | ||
- [Model versions](model-versions) ([#2841](https://github.com/dbt-labs/docs.getdbt.com/issues/2841)) | ||
|
||
### dbt-core Python API | ||
- Auto-generated documentation ([#2674](https://github.com/dbt-labs/docs.getdbt.com/issues/2674)) for dbt-core CLI & Python API for programmatic invocations |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No functional change here, I just reordered the list so it's in a consistent (descending) order by
firstVersion
. I figure, in the future, we could remove items from this list as we deprecate older versions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!