-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* bug/renamed-columns * add macro file * add casting * update yml * add casting for all * macro updates * bug/renamed-columns-dynamic * adjustments * add consistency tests * update yml * bug/renamed-columns-option3 * rename variables for readability * adjust casts * update yml * update version & changelog * update variable for readbility * small adjustment * revise consistency test * update changelog * update test * update changelog * update test & macro * update changelog * make breaking * regen docs * update packages * update test * update comments
- Loading branch information
1 parent
b41bbcc
commit 197838b
Showing
35 changed files
with
542 additions
and
382 deletions.
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
target/ | ||
dbt_modules/ | ||
logs/ | ||
env/ | ||
env/ | ||
package-lock.yml |
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
62 changes: 62 additions & 0 deletions
62
integration_tests/tests/consistency/consistency_all_tables_and_columns.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,62 @@ | ||
{{ config( | ||
tags="fivetran_validations", | ||
enabled=var('fivetran_validation_tests_enabled', false) | ||
) }} | ||
|
||
/* This test is to make sure the final columns produced are the same between versions. | ||
Only one test is needed since it will fetch all tables and all columns in each schema. | ||
!!! THIS TEST IS WRITTEN FOR BIGQUERY!!! */ | ||
{% if target.type == 'bigquery' %} | ||
with prod as ( | ||
select | ||
table_name, | ||
column_name, | ||
data_type | ||
from {{ target.schema }}_salesforce_source_prod.INFORMATION_SCHEMA.COLUMNS | ||
where table_name like 'stg_%' | ||
), | ||
|
||
dev as ( | ||
select | ||
table_name, | ||
column_name, | ||
data_type | ||
from {{ target.schema }}_salesforce_source_dev.INFORMATION_SCHEMA.COLUMNS | ||
where table_name like 'stg_%' | ||
), | ||
|
||
prod_not_in_dev as ( | ||
-- rows from prod not found in dev | ||
select * from prod | ||
except distinct | ||
select * from dev | ||
), | ||
|
||
dev_not_in_prod as ( | ||
-- rows from dev not found in prod | ||
select * from dev | ||
except distinct | ||
select * from prod | ||
), | ||
|
||
final as ( | ||
select | ||
*, | ||
'from prod' as source | ||
from prod_not_in_dev | ||
|
||
union all -- union since we only care if rows are produced | ||
|
||
select | ||
*, | ||
'from dev' as source | ||
from dev_not_in_prod | ||
) | ||
|
||
select * | ||
from final | ||
|
||
{% else %} | ||
{{ print('This is written to run on bigquery. If you need to run on another warehouse, add a version!') }} | ||
|
||
{% endif %} |
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,24 @@ | ||
{% macro add_renamed_columns(column_list) %} | ||
{# This macro determines the original names for each column and adds them to the list generated within each `get_*_columns` macro. By default, this macro processes column names by removing underscores and capitalizing each part that follows an underscore. This ensures all necessary columns are available for use in the `coalesce_rename` macro. Additionally, this macro tags each column with its renamed version to maintain tracking. #} | ||
|
||
{%- set renamed_columns = [] %} | ||
|
||
{%- for col in column_list %} | ||
|
||
{%- set original_column_name = col.name %} | ||
|
||
{%- if 'fivetran' not in original_column_name %} | ||
{# Use renamed_column_name value if it provided in the get_columns macro #} | ||
{%- set renamed_column_name = col.renamed_column_name | default(original_column_name.split('_') | map('capitalize') | join('')) %} | ||
|
||
{# Add an entry to the list of renames to populate the filled columns if the rename is different #} | ||
{%- do renamed_columns.append({"name": renamed_column_name, "datatype": col.datatype, "is_rename": true}) if renamed_column_name|lower != original_column_name|lower %} | ||
|
||
{# Update the original column with the renamed column name for use later. #} | ||
{%- set col = col.update({ "renamed_column_name": renamed_column_name, "is_rename": false}) %} | ||
{%- endif %} | ||
{%- endfor %} | ||
|
||
{%- do column_list.extend(renamed_columns) %} | ||
|
||
{% endmacro %} |
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,21 @@ | ||
{% macro coalesce_rename( | ||
column_key, | ||
column_dict, | ||
original_column_name=column_dict[column_key]["name"], | ||
datatype=column_dict[column_key]["datatype"], | ||
alias=column_dict[column_key]["alias"] | default(original_column_name), | ||
renamed_column_name=column_dict[column_key]["renamed_column_name"] | ||
) %} | ||
|
||
{# This macro accomodates Fivetran connectors that keep the original salesforce field naming conventions without underscores #} | ||
{# Utilizes the dictionary generated by `column_list_to_dict` to coalesce a column with its renamed counterpart, producing the final column. This macro also allows for the passing of a custom renamed spelling, datatype, and alias as arguments to override default values. #} | ||
{%- if original_column_name|lower == renamed_column_name|lower %} | ||
cast({{ renamed_column_name }} as {{ datatype }}) as {{ alias }} | ||
|
||
{%- else %} | ||
coalesce(cast({{ renamed_column_name }} as {{ datatype }}), | ||
cast({{ original_column_name }} as {{ datatype }})) | ||
as {{ alias }} | ||
|
||
{%- endif %} | ||
{%- endmacro %} |
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,9 @@ | ||
{% macro column_list_to_dict(column_list) %} | ||
{# This macro converts the list of dictionaries generated by the `get_*_columns` macros into a dictionary of dictionaries for use in the `coalesce_rename` macro. This conversion is necessary so that each column dictionary entry can be accessed by a key, rather than iterating through a list. #} | ||
{%- set column_dict = {} -%} | ||
{%- for col in column_list -%} | ||
{%- do column_dict.update({col.name: col}) if not col.is_rename -%} | ||
{%- endfor -%} | ||
{{ return(column_dict) }} | ||
|
||
{% endmacro %} |
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
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
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
Oops, something went wrong.