Skip to content

Commit

Permalink
Adding
Browse files Browse the repository at this point in the history
  • Loading branch information
Sachin-Thakur committed Oct 31, 2023
1 parent 779cc4e commit 899c332
Show file tree
Hide file tree
Showing 2 changed files with 211 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dbt/adapters/vertica/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,5 @@ def get_incremental_strategy_macro(self, model_context, strategy: str):

# This returns a callable macro
return model_context[macro_name]
def debug_query(self) -> None:
self.execute("select 1 as id")
209 changes: 209 additions & 0 deletions tests/functional/adapter/constraints/test_constraints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
from dbt.tests.adapter.utils.test_null_compare import BaseNullCompare
from dbt.tests.adapter.utils.test_null_compare import BaseMixedNullCompare

from dbt.tests.adapter.constraints.test_constraints import BaseIncrementalConstraintsRollback
from dbt.tests.adapter.utils.test_equals import BaseEquals
from dbt.tests.adapter.utils.test_validate_sql import BaseValidateSqlMethod

from dbt.tests.adapter.constraints.test_constraints import BaseModelConstraintsRuntimeEnforcement
from dbt.tests.adapter.constraints.test_constraints import BaseConstraintQuotedColumn



import pytest



# model breaking constraints
my_model_with_nulls_sql = """
{{
config(
materialized = "table"
)
}}
select
cast(null as {{ dbt.type_int() }}) as id,
'red' as color,
'2019-01-01' as date_day
"""


my_model_sql = """
{{
config(
materialized = "table"
)
}}
select
1 as id,
'blue' as color,
'2019-01-01' as date_day
"""



model_schema_yml = """
version: 2
models:
- name: my_model
config:
contract:
enforced: true
columns:
- name: id
data_type: integer
description: hello
constraints:
- type: not_null
- type: primary_key
- type: check
expression: (id > 0)
- type: check
expression: id >= 1
tests:
- unique
- name: color
data_type: text
- name: date_day
data_type: text
- name: my_model_error
config:
contract:
enforced: true
columns:
- name: id
data_type: integer
description: hello
constraints:
- type: not_null
- type: primary_key
- type: check
expression: (id > 0)
tests:
- unique
- name: color
data_type: text
- name: date_day
data_type: text
- name: my_model_wrong_order
config:
contract:
enforced: true
columns:
- name: id
data_type: integer
description: hello
constraints:
- type: not_null
- type: primary_key
- type: check
expression: (id > 0)
tests:
- unique
- name: color
data_type: text
- name: date_day
data_type: text
- name: my_model_wrong_name
config:
contract:
enforced: true
columns:
- name: id
data_type: integer
description: hello
constraints:
- type: not_null
- type: primary_key
- type: check
expression: (id > 0)
tests:
- unique
- name: color
data_type: text
- name: date_day
data_type: text
"""


class TestIncrementalConstraintsRollback(BaseIncrementalConstraintsRollback):

@pytest.fixture(scope="class")
def models(self):
return {
"my_model.sql": my_model_sql,
"constraints_schema.yml": model_schema_yml,
}
@pytest.fixture(scope="class")
def expected_error_messages(self):
return [""]

@pytest.fixture(scope="class")
def expected_color(self):
return "red"

@pytest.fixture(scope="class")
def null_model_sql(self):
return my_model_with_nulls_sql





class TestValidateSqlMethod(BaseValidateSqlMethod):
pass

class TestNullCompare(BaseNullCompare):
pass


class TestMixedNullCompare(BaseMixedNullCompare):
pass


class TestEquals(BaseEquals):
pass




class TestConstraintQuotedColumn(BaseConstraintQuotedColumn):
@pytest.fixture(scope="class")
def expected_sql(self):
return """
create table <model_identifier> include schema privileges as(select 'blue' as "from",1 as id,'2019-01-01' as date_day);
"""
pass

class TestModelConstraintsRuntimeEnforcement(BaseModelConstraintsRuntimeEnforcement):
@pytest.fixture(scope="class")
def expected_sql(self):
return """
create table <model_identifier> (
id integer not null,
color text,
date_day text,
primary key (id),
constraint strange_uniqueness_requirement unique (color, date_day),
foreign key (id) references <foreign_key_model_identifier> (id)
) ;
insert into <model_identifier>
(
select
id,
color,
date_day from
(
-- depends_on: <foreign_key_model_identifier>
select
'blue' as color,
1 as id,
'2019-01-01' as date_day
) as model_subq
)
;
"""

0 comments on commit 899c332

Please sign in to comment.