Skip to content

Commit

Permalink
Modify adapter to support unified constraint fields (#522)
Browse files Browse the repository at this point in the history
* ct-2212: Adjust adapter implementation for unified constraint properties

* CT-2212: Add changelog entry and make minor message tweak

* CT-2212: Add temporary branch pin

* CT-2212: Tweak constraint generation to use new adapter method

* CT-2212: Revert requirement in preparation for merge
  • Loading branch information
peterallenwebb authored Mar 22, 2023
1 parent 41cf043 commit d3589a9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230314-123129.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Unified pre-release condition and condition_check properties
time: 2023-03-14T12:31:29.395869-04:00
custom:
Author: peterallenwebb
Issue: "491"
20 changes: 13 additions & 7 deletions dbt/include/snowflake/macros/utils/get_columns_spec_ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
{%- set ns = namespace(at_least_one_check=False) -%}
{%- set user_provided_columns = model['columns'] -%}
(
{% for i in user_provided_columns -%}
{% 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['constraints_check'] %}
{{ col['name'] }} {{ col['data_type'] }} {% for x in constraints %} {{ x or "" }} {% endfor %} {{ "," if not loop.last }}
{%- endfor %}
)
{%- set constraints = col['constraints'] -%}
{{ col['name'] }} {{ col['data_type'] }}
{%- for c in constraints -%}
{%- if c.type == "check" -%}
{%- set ns.at_least_one_check = True -%}
{%- else %} {{ adapter.render_raw_column_constraint(c) }}
{%- endif -%}
{%- endfor -%}
{{ "," if not loop.last }}
{% endfor -%}
)
{%- if ns.at_least_one_check -%}
{{exceptions.warn("We noticed you have `constraints_check` configs, these are NOT compatible with Snowflake and will be ignored")}}
{{exceptions.warn("We noticed you have check constraints in your configs, these are NOT compatible with Snowflake and will be ignored")}}
{%- endif %}
{% endmacro %}
4 changes: 2 additions & 2 deletions tests/functional/adapter/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

_expected_sql_snowflake = """
create or replace transient table {0} (
id integer not null primary key ,
color text ,
id integer not null primary key,
color text,
date_day text
) as ( select
id,
Expand Down

0 comments on commit d3589a9

Please sign in to comment.