-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CT 2196, CT2121 constraints column order #7161
Changes from all commits
b3002e1
e257ef1
4d06b6c
d64810b
7780040
bbc18b7
561a4a7
3ea1c0a
39fa7b1
852a4b8
bdd555f
6a98e60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: Make model contracts agnostic to ordering | ||
time: 2023-03-13T13:59:17.255368-04:00 | ||
custom: | ||
Author: gshank | ||
Issue: 6975 7064 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,11 +25,26 @@ | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking through what this might look like across all potential adapters, and if we need to add contract-related items in the future. With that context, I have the following questions:
With my assumptions (not necessarily true of course): {% macro default__create_table_as(temporary, relation, sql) -%}
{% if config.get('contract', False) %}
{{ default__create_table_as_with_contract(temporary, relation, sql }}
{% else %}
{{ default__create_table_as_without_contract(temporary, relation, sql }}
{% endif %}
{% endmacro %}
{% macro default__create_table_as_with_contract(temporary, relation, sql) %}
{{ get_assert_columns_equivalent(sql) }}
create {% if temporary: -%}temporary{%- endif %} table
{{ relation.include(database=(not temporary), schema=(not temporary)) }}
{{ get_columns_spec_ddl() }}
as ({{ sql }})
{% endmacro %}
{% macro default__create_table_as_without_contract(temporary, relation, sql) %}
create {% if temporary: -%}temporary{%- endif %} table
{{ relation.include(database=(not temporary), schema=(not temporary)) }}
as ({{ sql }})
{% endmacro %} This would maintain backwards compatibility because we're keeping the macro There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need the get_select_subquery in order to put the columns in the right order. We removed validating the order because we added the subquery. As far as splitting out the macro into two, probably @jtcohen6 and @MichelleArk should weigh in on that. |
||
create {% if temporary: -%}temporary{%- endif %} table | ||
{{ relation.include(database=(not temporary), schema=(not temporary)) }} | ||
{% if config.get('contract', False) %} | ||
{{ get_assert_columns_equivalent(sql) }} | ||
{{ get_columns_spec_ddl() }} | ||
{% endif %} | ||
{% if config.get('contract', False) %} | ||
{{ get_assert_columns_equivalent(sql) }} | ||
{{ get_columns_spec_ddl() }} | ||
{%- set sql = get_select_subquery(sql) %} | ||
{% endif %} | ||
as ( | ||
{{ sql }} | ||
); | ||
{%- endmacro %} | ||
|
||
{% macro get_select_subquery(sql) %} | ||
{{ return(adapter.dispatch('get_select_subquery', 'dbt')(sql)) }} | ||
{% endmacro %} | ||
|
||
{% macro default__get_select_subquery(sql) %} | ||
select | ||
{% for column in model['columns'] %} | ||
{{ column }}{{ ", " if not loop.last }} | ||
{% endfor %} | ||
from ( | ||
{{ sql }} | ||
) as model_subq | ||
{%- endmacro %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be useful to sort these both alphabetically (message only) so that it's easier for the user to spot the difference.