-
Notifications
You must be signed in to change notification settings - Fork 159
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
dbt Constraints / model contracts #426
Conversation
Thanks for your pull request, and welcome to our community! We require contributors to sign our Contributor License Agreement and we don't seem to have your signature on file. Check out this article for more information on why we have a CLA. In order for us to review and merge your code, please submit the Individual Contributor License Agreement form attached above above. If you have questions about the CLA, or if you believe you've received this message in error, don't hesitate to ping @drewbanin. CLA has not been signed by users: @Victoriapm |
Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the dbt-bigquery contributing guide. |
tests/functional/adapter/constraints/test_bigquery_constraints.py
Outdated
Show resolved
Hide resolved
|
||
def test__constraints_enforcement(self, project): | ||
|
||
results, log_output = run_dbt_and_capture(['run', '-s', 'my_model_error'], expect_pass=False) |
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.
Run the raw sql DDL manually against a bigquery instance to debug why it's running successfully: https://github.com/dbt-labs/dbt-bigquery/actions/runs/3744300377/jobs/6357515726#step:7:755
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.
DDL runs in BQ, also config +models run as expected according to the test in a dbt project where I've been testing this
with open("./models/my_model.sql", "w") as fp: | ||
fp.write(my_model_sql_error) | ||
|
||
results = run_dbt(["run", "-s", "my_model"], expect_pass=False) |
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.
Run the raw sql DDL manually against a bigquery instance to debug why it's running successfully: https://github.com/dbt-labs/dbt-bigquery/actions/runs/3744300377/jobs/6357515726#step:7:653
tests/functional/adapter/constraints/test_bigquery_constraints.py
Outdated
Show resolved
Hide resolved
tests/functional/adapter/constraints/test_bigquery_constraints.py
Outdated
Show resolved
Hide resolved
tests/functional/adapter/constraints/test_bigquery_constraints.py
Outdated
Show resolved
Hide resolved
tests/functional/adapter/constraints/test_bigquery_constraints.py
Outdated
Show resolved
Hide resolved
This test is failing because the schema configs you import from the existing tests has |
{% for i in user_provided_columns -%} | ||
{%- set col = user_provided_columns[i] -%} | ||
{% set constraints = col['constraints'] -%} | ||
{%- set ns.at_least_one_check = ns.at_least_one_check or col['check'] %} |
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.
{%- set ns.at_least_one_check = ns.at_least_one_check or col['check'] %} | |
{%- set ns.at_least_one_check = ns.at_least_one_check or col['constraints_check'] %} |
Do a find and replace on all check
configs in all files to be constraints_check
by name.
@@ -52,8 +52,10 @@ | |||
{{ sql_header if sql_header is not none }} | |||
|
|||
create or replace table {{ relation }} | |||
{{ get_columns_spec_ddl() }} |
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.
{{ get_columns_spec_ddl() }} | |
{{ get_columns_spec_ddl() }} | |
{{ get_assert_columns_equivalent(sql) }} |
This creates a validation check that columns in a sql statement match the schema config
@@ -0,0 +1,18 @@ | |||
{% macro bigquery__get_columns_spec_ddl() %} | |||
{# loop through user_provided_columns to create DDL with data types and constraints #} | |||
{% if config.get('constraints_enabled', False) %} |
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.
Move this if statement to adapters.sql
similar to this: https://github.com/dbt-labs/dbt-core/pull/6271/files#diff-7246f19f4d12042d172ac61b3d0c4564ea27dd8825870b35425ede1ea41625dbR28
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.
Looks like the if statement been added to adapters.sql, and can now be deleted from this macro.
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.
Good catch!
@Victoriapm @sungchun12 I'm supposing this is still being worked on. |
@Victoriapm can you cross-check the other adapter PRs, and update this branch with additional changes as needed? |
Co-authored-by: Sung Won Chung <sungwonchung3@gmail.com>
2d0ab85
to
6c46db4
Compare
resolves #444
Related to dbt-core issue #6079, allowing to define constraints and data types in model config for BigQuery
Related to #6271
Description
not null
constraint, others likecheck
, will failRelated Core/Adapter Pull Requests
Checklist
changie new
to create a changelog entry