-
Notifications
You must be signed in to change notification settings - Fork 4
test/custom-naming #35
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
Open
fivetran-catfritz
wants to merge
20
commits into
main
Choose a base branch
from
test/custom-naming
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4b8541b
test/custom-naming
fivetran-catfritz 5ec6afd
yml
fivetran-catfritz 884a785
pre-exit
fivetran-catfritz bda1cff
pre-exit
fivetran-catfritz a87200d
undo pre-exit
fivetran-catfritz 2c0819c
revise var names
fivetran-catfritz 4b7aa19
revise var names
fivetran-catfritz 9fe483f
revise var names
fivetran-catfritz fd0b474
revise macro
fivetran-catfritz 012f58e
revise macro
fivetran-catfritz ae3c6e1
update stg
fivetran-catfritz be36b35
add macro
fivetran-catfritz dddf838
add fix yml
fivetran-catfritz 270883f
fix yml
fivetran-catfritz 2d5ca1f
fix yml
fivetran-catfritz db927b7
adjust select placement
fivetran-catfritz 6e256ed
considering aliases
fivetran-catfritz 244ced2
merge
fivetran-catfritz badae60
testing
fivetran-catfritz c1db544
testing
fivetran-catfritz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| id,last_updated_date,_fivetran_synced,campaign_id,creation_date,default_bid,name,serving_status,state | ||
| id,last_updated_date,_fivetran_synced,campaign_id,creationDate,defaultBid,name,serving_status,state | ||
| 421,2022-07-11 22:38:16.551000,2022-12-13 17:10:16.297000,2187,2022-07-11 22:38:16.551000,1.75,Red 7,CAMPAIGN_PAUSED,enabled | ||
| 501,2022-11-09 14:37:05.332000,2022-12-13 17:11:08.594000,5555,2022-11-09 14:37:05.332000,1.45,All,AD_GROUP_STATUS_ENABLED,enabled |
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...ion_tests/seeds/campaign_history_data.csv → integration_tests/seeds/campaign_history.csv
This file contains hidden or 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 hidden or 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 hidden or 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,55 @@ | ||
| {% macro resolve_column_names(_fivetran_table_name, columns, package_name='amazon_ads') %} | ||
| {#- | ||
| Resolves custom column name mappings for a given table across all configured schemas. | ||
|
|
||
| This macro creates a complete mapping of standard column names to their possible variants | ||
| (both custom names and standard names) for use in column standardization. | ||
|
|
||
| Args: | ||
| _fivetran_table_name: The base table name (e.g., 'ad_group_level_report') | ||
| columns: List of column objects with 'name' and 'datatype' attributes | ||
| package_name: Package name for variable lookup (default: 'amazon_ads') | ||
|
|
||
| Returns: | ||
| Dict mapping standard names to lists of possible column names. | ||
|
|
||
| Example output for campaign_bidding_strategy with custom mapping: | ||
| { | ||
| "campaign_bidding_strategy": ["campaignBiddingStrategy", "campaign_bidding_strategy"], | ||
| "ad_group_id": ["ad_group_id"], | ||
| "clicks": ["clicks"] | ||
| } | ||
| -#} | ||
| {{ return(adapter.dispatch('resolve_column_names', 'amazon_ads')(_fivetran_table_name, columns, package_name)) }} | ||
| {% endmacro %} | ||
|
|
||
| {% macro default__resolve_column_names(_fivetran_table_name, columns, package_name) %} | ||
|
|
||
| {% if var(package_name ~ '_using_custom_names', false) %} | ||
| {# Step 1: Get the custom column name configuration from variables #} | ||
| {% set custom_column_names = var(package_name ~ '_custom_column_names', {}) %} | ||
| {% set column_name_mappings = {} %} | ||
|
|
||
| {# Step 2: Process each expected column to build complete name mappings #} | ||
| {% for column in columns %} | ||
| {% set standard_name = column.name %} | ||
| {% set custom_names = [] %} | ||
|
|
||
| {# Step 3: Look through all schemas for custom names for this standard field #} | ||
| {% for schema_name, custom_cols_for_schema in custom_column_names.items() %} | ||
| {% set custom_name = custom_cols_for_schema.get(_fivetran_table_name, {}).get(standard_name, false) %} | ||
| {% do custom_names.append(custom_name) if custom_name and custom_name not in custom_names %} | ||
| {% endfor %} | ||
|
|
||
| {# Step 4: Create complete name list (custom names first, then standard as fallback) #} | ||
| {% set all_names = custom_names + [standard_name] if custom_names else [standard_name] %} | ||
| {% do column_name_mappings.update({standard_name: all_names}) %} | ||
| {% endfor %} | ||
|
|
||
| {{ return(column_name_mappings) }} | ||
| {% else %} | ||
| {# Custom names not enabled - return empty dict #} | ||
| {{ return({}) }} | ||
| {% endif %} | ||
|
|
||
| {% endmacro %} |
This file contains hidden or 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,71 @@ | ||
| {% macro standardize_column_names(tmp_relation, table_name, base_columns, package_name='amazon_ads') %} | ||
| {#- | ||
| Standardizes column names from source tables with mixed naming conventions. | ||
|
|
||
| This macro handles both column name standardization (coalescing custom names to | ||
| standard names) and missing column filling (creating NULLs for expected columns | ||
| that don't exist in the source). | ||
|
|
||
| Args: | ||
| tmp_relation: The source relation (typically from tmp staging model) | ||
| table_name: The base table name for custom name lookups | ||
| base_columns: List of expected column objects with 'name' and 'datatype' | ||
| package_name: Package name for variable lookup (default: 'amazon_ads') | ||
|
|
||
| Returns: | ||
| SQL select statement with standardized column names. | ||
|
|
||
| Example output: | ||
| select | ||
| coalesce("campaignBiddingStrategy", "campaign_bidding_strategy") as campaign_bidding_strategy, | ||
| "ad_group_id" as ad_group_id, | ||
| cast(null as integer) as missing_column | ||
| from tmp_relation | ||
| -#} | ||
| {{ return(adapter.dispatch('standardize_column_names', 'amazon_ads')(tmp_relation, table_name, base_columns, package_name)) }} | ||
| {% endmacro %} | ||
|
|
||
| {% macro default__standardize_column_names(tmp_relation, table_name, base_columns, package_name) %} | ||
|
|
||
| {# Step 1: Inspect the source relation to see what columns actually exist #} | ||
| {%- set actual_columns = adapter.get_columns_in_relation(tmp_relation) %} | ||
| {%- set actual_column_names = actual_columns | map(attribute='name') | list %} | ||
|
|
||
| {# Step 2: Get custom name mappings for this table if custom names are enabled #} | ||
| {%- set custom_mappings = amazon_ads.resolve_column_names(table_name, base_columns, package_name) if var(package_name ~ '_using_custom_names', false) else {} %} | ||
|
|
||
| {# Step 3: Process each expected column to generate standardized select statements #} | ||
| {%- for column in base_columns %} | ||
| {%- set standard_name = column.name %} | ||
| {%- set column_datatype = column.datatype %} | ||
| {%- set column_alias = column.alias if column.alias else standard_name %} | ||
|
|
||
| {%- if standard_name in custom_mappings -%} | ||
| {# Step 3a: Column has custom mappings - check which variants actually exist #} | ||
| {%- set available_variants = [] -%} | ||
| {%- for variant in custom_mappings[standard_name] if variant|lower in actual_column_names|map('lower') -%} | ||
| {%- do available_variants.append(variant) -%} | ||
| {%- endfor -%} | ||
|
|
||
| {%- if available_variants|length > 1 -%} | ||
| coalesce({{ available_variants | join(', ') }}) | ||
| {%- elif available_variants|length == 1 -%} | ||
| {{ available_variants[0] }} | ||
| {%- else -%} | ||
| cast(null as {{ column_datatype }}) | ||
| {%- endif %} | ||
|
|
||
| {%- else -%} | ||
| {# Step 3b: Column has no custom mappings - check if standard name exists #} | ||
| {%- if standard_name in actual_column_names -%} | ||
| {{ standard_name }} | ||
| {%- else -%} | ||
| cast(null as {{ column_datatype }}) | ||
| {%- endif %} | ||
| {% endif %} | ||
|
|
||
| as {{ column_alias }}{{ ',' if not loop.last }} | ||
|
|
||
| {% endfor %} | ||
|
|
||
| {% endmacro %} |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
for testing