-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add option to remove the source_column_name on the union_rel…
…ations macro (#624) * Changed the union macro to function with `none` as an argument * Updated the README with the new functionality * Added to the CHANGELOG * Update README.md * Added integration test for omitting source column on union_relations macro * Update integration_tests/tests/generic/expect_table_columns_to_match_set.sql
- Loading branch information
1 parent
fbbc0fb
commit 162a15c
Showing
6 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{{ dbt_utils.union_relations([ | ||
ref('data_union_table_1'), | ||
ref('data_union_table_2') | ||
], | ||
source_column_name = none | ||
) }} |
54 changes: 54 additions & 0 deletions
54
integration_tests/tests/generic/expect_table_columns_to_match_set.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{# | ||
This macro is copied and slightly edited from the dbt_expectations package. | ||
At the time of this addition, dbt_expectations couldn't be added because | ||
integration_tests is installing dbt_utils from local without a hard-coded | ||
path. dbt is not able to resolve duplicate dependencies of dbt_utils | ||
due to this. | ||
#} | ||
{%- test expect_table_columns_to_match_set(model, column_list, transform="upper") -%} | ||
{%- if execute -%} | ||
{%- set column_list = column_list | map(transform) | list -%} | ||
{# Replaces dbt_expectations._get_column_list() #} | ||
{%- set relation_column_names = adapter.get_columns_in_relation(model) | ||
| map(attribute="name") | ||
| map(transform) | ||
| list | ||
-%} | ||
{# Replaces dbt_expectations._list_intersect() #} | ||
{%- set matching_columns = [] -%} | ||
{%- for itm in column_list -%} | ||
{%- if itm in relation_column_names -%} | ||
{%- do matching_columns.append(itm) -%} | ||
{%- endif -%} | ||
{%- endfor -%} | ||
with relation_columns as ( | ||
{% for col_name in relation_column_names %} | ||
select cast('{{ col_name }}' as {{ dbt_utils.type_string() }}) as relation_column | ||
{% if not loop.last %}union all{% endif %} | ||
{% endfor %} | ||
), | ||
input_columns as ( | ||
{% for col_name in column_list %} | ||
select cast('{{ col_name }}' as {{ dbt_utils.type_string() }}) as input_column | ||
{% if not loop.last %}union all{% endif %} | ||
{% endfor %} | ||
) | ||
select * | ||
from | ||
relation_columns r | ||
full outer join | ||
input_columns i on r.relation_column = i.input_column | ||
where | ||
-- catch any column in input list that is not in the list of table columns | ||
-- or any table column that is not in the input list | ||
r.relation_column is null or | ||
i.input_column is null | ||
{%- endif -%} | ||
{%- endtest -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters