Skip to content

Commit

Permalink
support contracts on models materialized as view (#500)
Browse files Browse the repository at this point in the history
* first pass with contract check

* rename test class

* file merge cleanup

* clean up tests

* changelog

* fix class name

* remove dbt-core pin
  • Loading branch information
emmyoop authored Mar 8, 2023
1 parent 967a8e9 commit 9d2f8f3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .changes/unreleased/Features-20230223-182450.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kind: Features
body: implement data_type_code_to_name on SnowflakeConnectionManager
body: Enforce contracts on models materialized as tables and views
time: 2023-02-23T18:24:50.272955-05:00
custom:
Author: michelleark
Issue: "464"
Author: michelleark emmyoop
Issue: 464 490
3 changes: 3 additions & 0 deletions dbt/include/snowflake/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
{{ get_persist_docs_column_list(model_columns, query_columns) }}

{%- endif %}
{% if config.get('contract', False) -%}
{{ get_assert_columns_equivalent(sql) }}
{%- endif %}
{% if copy_grants -%} copy grants {%- endif %} as (
{{ sql }}
);
Expand Down
13 changes: 10 additions & 3 deletions tests/functional/adapter/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from dbt.tests.util import relation_from_name
from dbt.tests.adapter.constraints.test_constraints import (
BaseConstraintsColumnsEqual,
BaseTableConstraintsColumnsEqual,
BaseViewConstraintsColumnsEqual,
BaseConstraintsRuntimeEnforcement
)

Expand All @@ -21,8 +22,7 @@
"""


class TestSnowflakeConstraintsColumnsEqual(BaseConstraintsColumnsEqual):

class SnowflakeColumnEqualSetup:
@pytest.fixture
def int_type(self):
return "FIXED"
Expand All @@ -46,6 +46,13 @@ def data_types(self, int_type, schema_int_type, string_type):
["""TO_VARIANT(PARSE_JSON('{"key3": "value3", "key4": "value4"}'))""", 'variant', 'VARIANT'],
]

class TestSnowflakeTableConstraintsColumnsEqual(SnowflakeColumnEqualSetup, BaseTableConstraintsColumnsEqual):
pass


class TestSnowflakeViewConstraintsColumnsEqual(SnowflakeColumnEqualSetup, BaseViewConstraintsColumnsEqual):
pass


class TestSnowflakeConstraintsRuntimeEnforcement(BaseConstraintsRuntimeEnforcement):

Expand Down

0 comments on commit 9d2f8f3

Please sign in to comment.