Skip to content

Commit

Permalink
support contracts on models materialized as view dbt-labs#584 (dbt-la…
Browse files Browse the repository at this point in the history
…bs#360)

* first pass with contract check

* rename test class

* clean up test

* point to branch

* fix whitespace

* fix class name

* remove dbt-core pin
  • Loading branch information
emmyoop authored Mar 8, 2023
1 parent 648a00c commit 565549a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .changes/unreleased/Features-20230301-113553.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kind: Features
body: Implemented data_type_code_to_name for redshift
body: Enforce contracts on models materialized as tables and views
time: 2023-03-01T11:35:53.98885-05:00
custom:
Author: peterallenwebb
Issue: "319"
Author: peterallenwebb emmyoop
Issue: 319 340
5 changes: 4 additions & 1 deletion dbt/include/redshift/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@

{{ sql_header if sql_header is not none }}

create view {{ relation }} as (
create view {{ relation }}
{% if config.get('contract', False) -%}
{{ get_assert_columns_equivalent(sql) }}
{%- endif %} as (
{{ sql }}
) {{ bind_qualifier }};
{% endmacro %}
Expand Down
12 changes: 10 additions & 2 deletions tests/functional/adapter/test_constraints.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
from dbt.tests.util import relation_from_name
from dbt.tests.adapter.constraints.test_constraints import (
BaseConstraintsColumnsEqual,
BaseTableConstraintsColumnsEqual,
BaseViewConstraintsColumnsEqual,
BaseConstraintsRuntimeEnforcement
)

Expand All @@ -23,7 +24,7 @@
"""


class TestRedshiftConstraintsColumnsEqual(BaseConstraintsColumnsEqual):
class RedshiftColumnEqualSetup:
@pytest.fixture
def data_types(self, schema_int_type, int_type, string_type):
# NOTE: Unlike some other adapters, we don't test array or JSON types here, because
Expand All @@ -41,6 +42,13 @@ def data_types(self, schema_int_type, int_type, string_type):
]


class TestRedshiftTableConstraintsColumnsEqual(RedshiftColumnEqualSetup, BaseTableConstraintsColumnsEqual):
pass


class TestRedshiftViewConstraintsColumnsEqual(RedshiftColumnEqualSetup, BaseViewConstraintsColumnsEqual):
pass

class TestRedshiftConstraintsRuntimeEnforcement(BaseConstraintsRuntimeEnforcement):
@pytest.fixture(scope="class")
def expected_sql(self, project):
Expand Down

0 comments on commit 565549a

Please sign in to comment.