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

Model contract (#336) #339

Merged
merged 3 commits into from
May 10, 2023
Merged

Model contract (#336) #339

merged 3 commits into from
May 10, 2023

Conversation

andrefurlan-db
Copy link
Collaborator

@andrefurlan-db andrefurlan-db commented May 10, 2023

Description

Support for dbt 1.5 model contracts Model Contracts When contract enforcement is enabled:

  • enforcement of column names/data types
  • support for check, non_null, and primary_key constraints defined at both model and column level

ex.

models:
  - name: table_model
    config:
      contract:
        enforced: true
    constraints:
      - type: check
        name: id_greater_than_zero
        expression: id > 0
        columns: [id]
      - type: not_null
        columns: [date]
    columns:
      - name: id
        data_type: int
        constraints:
          - type: primary_key
      - name: name
        data_type: string
        constraints:
          - type: not_null
      - name: date
        data_type: string
        constraints:
          - type: check
            name: date_check_constraint
            expression: date != '2020-12-12'

Checklist

  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change to the "dbt-databricks next" section.

### Description
Support for dbt 1.5 model contracts [Model Contracts](https://docs.getdbt.com/docs/collaborate/govern/model-contracts)
When contract enforcement is enabled:
- enforcement of column names/data types
- support for check, non_null, and primary_key constraints defined at both model and column level

ex.
```
models:
  - name: table_model
    config:
      contract:
        enforced: true
    constraints:
      - type: check
        name: id_greater_than_zero
        expression: id > 0
        columns: [id]
      - type: not_null
        columns: [date]
    columns:
      - name: id
        data_type: int
        constraints:
          - type: primary_key
      - name: name
        data_type: string
        constraints:
          - type: not_null
      - name: date
        data_type: string
        constraints:
          - type: check
            name: date_check_constraint
            expression: date != '2020-12-12'
```

### Checklist

- [X] I have run this code in development and it appears to resolve the stated issue
- [X] This PR includes tests, or tests are not required/relevant for this PR
- [X] I have updated the `CHANGELOG.md` and added information about my change to the "dbt-databricks next" section.


Signed-off-by: Raymond Cypher <raymond.cypher@databricks.com>
Disable TestModelContractNotDelta until it can be redesigned
Signed-off-by: Raymond Cypher <raymond.cypher@databricks.com>
@rcypher-databricks rcypher-databricks temporarily deployed to azure-prod-peco May 10, 2023 18:51 — with GitHub Actions Inactive
@rcypher-databricks rcypher-databricks temporarily deployed to azure-prod-pecou May 10, 2023 18:52 — with GitHub Actions Inactive
@andrefurlan-db andrefurlan-db merged commit 4d6e1ad into main May 10, 2023
@andrefurlan-db andrefurlan-db deleted the model_contract_staging branch May 10, 2023 20:58
@nikitasinghvi
Copy link

nikitasinghvi commented May 16, 2023

Thank you @andrefurlan-db for working on this issue 🙇‍♀️
I am facing a similar issue while using dbt-databricks. I discussed it with dbt-core team https://github.com/dbt-labs/dbt-core/discussions/7213#discussioncomment-5906418

Will your changes help with that? Also, any ETA for when this will be released 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants