Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
35070d7
bumping .latest branch variable in update_dependencies.sh to 1.5.latest
FishtownBuildBot Apr 13, 2023
8c8303d
[create-pull-request] automated change (#714)
github-actions[bot] Apr 17, 2023
c942e68
created 1.5.0rc1 changelog (#713)
mikealfare Apr 17, 2023
24c7792
ADAP-473: Table materialization not properly dropping existing relati…
github-actions[bot] Apr 21, 2023
45cc917
update docs for 1.5.0rc1 release (#728)
mikealfare Apr 22, 2023
7c70c36
[create-pull-request] automated change (#746)
github-actions[bot] Apr 27, 2023
8676b70
backport cce8975906ff5693d4c761ac32dc761f3f097a36 (#776)
emmyoop May 17, 2023
2ad6d2a
Finish Constraint Support for Spark (#747) (#795)
github-actions[bot] Jun 6, 2023
03d5d15
[Backport 1.5.latest] [Fix] Wrap constraint type 'check' expression i…
github-actions[bot] Jun 9, 2023
9d14652
backport 798 to 1.5.latest (#806)
MichelleArk Jun 14, 2023
2ec5ad6
[create-pull-request] automated change (#844)
github-actions[bot] Aug 1, 2023
7abad07
[create-pull-request] automated change (#854)
github-actions[bot] Aug 7, 2023
b4c76c6
Allow for scala models to be created
pekapa Sep 24, 2023
04713cf
Merge branch 'main' into submit-scala-jobs-beta
pekapa Sep 24, 2023
d2a858e
Delete .changes/1.5.0.md
pekapa Sep 24, 2023
f056b64
Delete .changes/1.5.1.md
pekapa Sep 24, 2023
c3d81c3
Delete .changes/1.5.2.md
pekapa Sep 24, 2023
7ca66cc
Update CHANGELOG.md
pekapa Sep 24, 2023
ac050f8
Update CHANGELOG.md
pekapa Sep 24, 2023
a895f66
Update CHANGELOG.md
pekapa Sep 24, 2023
82314ba
Update CHANGELOG.md
pekapa Sep 24, 2023
0e32655
Update dev-requirements.txt
pekapa Sep 24, 2023
84e8b15
Update test_constraints.py
pekapa Sep 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Backport 1.5.latest] [Fix] Wrap constraint type 'check' expression i…
…n parentheses (#797)
  • Loading branch information
github-actions[bot] authored Jun 9, 2023
commit 03d5d15163e1a974ed125b674752d777b9af237b
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230512-151453.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Wrap expression for check constraints in parentheses
time: 2023-05-12T15:14:53.151149-04:00
custom:
Author: michelleark
Issue: "7480"
2 changes: 1 addition & 1 deletion dbt/include/spark/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
{% if constraint.type == 'check' and not is_incremental() %}
{%- set constraint_hash = local_md5(column_name ~ ";" ~ constraint.expression ~ ";" ~ loop.index) -%}
{% call statement() %}
alter table {{ relation }} add constraint {{ constraint.name if constraint.name else constraint_hash }} check {{ constraint.expression }};
alter table {{ relation }} add constraint {{ constraint.name if constraint.name else constraint_hash }} check ({{ constraint.expression }});
{% endcall %}
{% endif %}
{% endfor %}
Expand Down
32 changes: 23 additions & 9 deletions tests/functional/adapter/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
my_model_incremental_wrong_order_sql,
my_model_incremental_wrong_name_sql,
my_incremental_model_sql,
model_fk_constraint_schema_yml,
my_model_wrong_order_depends_on_fk_sql,
foreign_key_model_sql,
my_model_incremental_wrong_order_depends_on_fk_sql,
)

# constraints are enforced via 'alter' statements that run after table creation
Expand All @@ -33,7 +37,9 @@
date_day
from

( select
(
-- depends_on: <foreign_key_model_identifier>
select
'blue' as color,
1 as id,
'2019-01-01' as date_day ) as model_subq
Expand All @@ -49,15 +55,20 @@
date_day
from

( select
1 as id,
(
-- depends_on: <foreign_key_model_identifier>
select
'blue' as color,
1 as id,
'2019-01-01' as date_day ) as model_subq
"""

# Different on Spark:
# - does not support a data type named 'text' (TODO handle this in the base test classes using string_type
constraints_yml = model_schema_yml.replace("text", "string").replace("primary key", "")
model_fk_constraint_schema_yml = model_fk_constraint_schema_yml.replace("text", "string").replace(
"primary key", ""
)
model_constraints_yml = constrained_model_schema_yml.replace("text", "string")


Expand Down Expand Up @@ -230,8 +241,9 @@ class TestSparkTableConstraintsDdlEnforcement(
@pytest.fixture(scope="class")
def models(self):
return {
"my_model.sql": my_model_wrong_order_sql,
"constraints_schema.yml": constraints_yml,
"my_model.sql": my_model_wrong_order_depends_on_fk_sql,
"foreign_key_model.sql": foreign_key_model_sql,
"constraints_schema.yml": model_fk_constraint_schema_yml,
}


Expand All @@ -242,8 +254,9 @@ class TestSparkIncrementalConstraintsDdlEnforcement(
@pytest.fixture(scope="class")
def models(self):
return {
"my_model.sql": my_model_incremental_wrong_order_sql,
"constraints_schema.yml": constraints_yml,
"my_model.sql": my_model_incremental_wrong_order_depends_on_fk_sql,
"foreign_key_model.sql": foreign_key_model_sql,
"constraints_schema.yml": model_fk_constraint_schema_yml,
}


Expand Down Expand Up @@ -324,8 +337,9 @@ def project_config_update(self):
@pytest.fixture(scope="class")
def models(self):
return {
"my_model.sql": my_incremental_model_sql,
"constraints_schema.yml": model_constraints_yml,
"my_model.sql": my_model_wrong_order_depends_on_fk_sql,
"foreign_key_model.sql": foreign_key_model_sql,
"constraints_schema.yml": model_fk_constraint_schema_yml,
}

@pytest.fixture(scope="class")
Expand Down