File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 156156{%- set derived_columns_to_select = datavault4dbt .process_columns_to_select (source_and_derived_column_names, hashed_column_names) | unique | list - %}
157157
158158{%- if datavault4dbt .is_something (derived_columns) %}
159+ {%- set overwrite_src_columns = datavault4dbt .extract_overwrite_columns (derived_columns) - %}
159160 {# - Getting Data types for derived columns with detection from source relation -#}
160161 {%- set derived_columns_with_datatypes = datavault4dbt .derived_columns_datatypes (derived_columns, source_relation) - %}
161162 {%- set derived_columns_with_datatypes_DICT = fromjson(derived_columns_with_datatypes) - %}
163+ {%- else - %}
164+ {%- set overwrite_src_columns = [] - %}
162165{%- endif - %}
163166{# - Select hashing algorithm -#}
164167
@@ -356,6 +359,7 @@ prejoined_columns AS (
356359derived_columns AS (
357360
358361 {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, derived_column_names) - %}
362+ {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, overwrite_src_columns) - %}
359363
360364 SELECT
361365 {% if final_columns_to_select | length > 0 - %}
Original file line number Diff line number Diff line change 156156{%- set derived_columns_to_select = datavault4dbt .process_columns_to_select (source_and_derived_column_names, hashed_column_names) | unique | list - %}
157157
158158{%- if datavault4dbt .is_something (derived_columns) %}
159+ {%- set overwrite_src_columns = datavault4dbt .extract_overwrite_columns (derived_columns) - %}
159160 {# - Getting Data types for derived columns with detection from source relation -#}
160161 {%- set derived_columns_with_datatypes = datavault4dbt .derived_columns_datatypes (derived_columns, source_relation) - %}
161162 {%- set derived_columns_with_datatypes_DICT = fromjson(derived_columns_with_datatypes) - %}
163+ {%- else - %}
164+ {%- set overwrite_src_columns = [] - %}
162165{%- endif - %}
163166{# - Select hashing algorithm -#}
164167
@@ -357,6 +360,7 @@ prejoined_columns AS (
357360derived_columns AS (
358361
359362 {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, derived_column_names) - %}
363+ {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, overwrite_src_columns) - %}
360364
361365 SELECT
362366
Original file line number Diff line number Diff line change 151151{%- set derived_columns_to_select = datavault4dbt .process_columns_to_select (source_and_derived_column_names, hashed_column_names) | unique | list - %}
152152
153153{%- if datavault4dbt .is_something (derived_columns) %}
154+ {%- set overwrite_src_columns = datavault4dbt .extract_overwrite_columns (derived_columns) - %}
154155 {# - Getting Data types for derived columns with detection from source relation -#}
155156 {%- set derived_columns_with_datatypes = datavault4dbt .derived_columns_datatypes (derived_columns, source_relation) - %}
156157 {%- set derived_columns_with_datatypes_DICT = fromjson(derived_columns_with_datatypes) - %}
158+ {%- else - %}
159+ {%- set overwrite_src_columns = [] - %}
157160{%- endif - %}
158161{# - Select hashing algorithm -#}
159162
@@ -352,6 +355,7 @@ prejoined_columns AS (
352355derived_columns AS (
353356
354357 {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, derived_column_names) - %}
358+ {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, overwrite_src_columns) - %}
355359
356360 SELECT
357361 {% if final_columns_to_select | length > 0 - %}
Original file line number Diff line number Diff line change 150150{%- set derived_columns_to_select = datavault4dbt .process_columns_to_select (source_and_derived_column_names, hashed_column_names) | unique | list - %}
151151
152152{%- if datavault4dbt .is_something (derived_columns) %}
153+ {%- set overwrite_src_columns = datavault4dbt .extract_overwrite_columns (derived_columns) - %}
153154 {# - Getting Data types for derived columns with detection from source relation -#}
154155 {%- set derived_columns_with_datatypes = datavault4dbt .derived_columns_datatypes (derived_columns, source_relation) - %}
155156 {%- set derived_columns_with_datatypes_DICT = fromjson(derived_columns_with_datatypes) - %}
157+ {%- else - %}
158+ {%- set overwrite_src_columns = [] - %}
156159{%- endif - %}
157160{# - Select hashing algorithm -#}
158161
@@ -362,6 +365,7 @@ derived_columns AS (
362365 {%- endif - %}
363366
364367 {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, exluded_derived_columns) - %}
368+ {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, overwrite_src_columns) - %}
365369
366370 SELECT
367371 {% if final_columns_to_select | length > 0 - %}
Original file line number Diff line number Diff line change 159159 {{ log(' derived_columns_to select : ' ~ derived_columns_to_select, false) }}
160160
161161{%- if datavault4dbt .is_something (derived_columns) %}
162+ {%- set overwrite_src_columns = datavault4dbt .extract_overwrite_columns (derived_columns) - %}
162163 {# - Getting Data types for derived columns with detection from source relation -#}
163164 {%- set derived_columns_with_datatypes = datavault4dbt .derived_columns_datatypes (derived_columns, source_relation) - %}
164165 {%- set derived_columns_with_datatypes_DICT = fromjson(derived_columns_with_datatypes) - %}
166+ {%- else - %}
167+ {%- set overwrite_src_columns = [] - %}
165168{%- endif - %}
166169{# - Select hashing algorithm -#}
167170
@@ -363,6 +366,7 @@ prejoined_columns AS (
363366derived_columns AS (
364367
365368 {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, derived_column_names) - %}
369+ {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, overwrite_src_columns) - %}
366370
367371 SELECT
368372 {% if final_columns_to_select | length > 0 - %}
Original file line number Diff line number Diff line change 156156{%- set derived_columns_to_select = datavault4dbt .process_columns_to_select (source_and_derived_column_names, hashed_column_names) | unique | list - %}
157157
158158{%- if datavault4dbt .is_something (derived_columns) %}
159+ {%- set overwrite_src_columns = datavault4dbt .extract_overwrite_columns (derived_columns) - %}
159160 {# - Getting Data types for derived columns with detection from source relation -#}
160161 {%- set derived_columns_with_datatypes = datavault4dbt .derived_columns_datatypes (derived_columns, source_relation) - %}
161162 {%- set derived_columns_with_datatypes_DICT = fromjson(derived_columns_with_datatypes) - %}
163+ {%- else - %}
164+ {%- set overwrite_src_columns = [] - %}
162165{%- endif - %}
163166{# - Select hashing algorithm -#}
164167
@@ -357,6 +360,7 @@ prejoined_columns AS (
357360derived_columns AS (
358361
359362 {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, derived_column_names) - %}
363+ {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, overwrite_src_columns) - %}
360364
361365 SELECT
362366 {% if final_columns_to_select | length > 0 - %}
Original file line number Diff line number Diff line change 156156{%- set derived_columns_to_select = datavault4dbt .process_columns_to_select (source_and_derived_column_names, hashed_column_names) | unique | list - %}
157157
158158{%- if datavault4dbt .is_something (derived_columns) %}
159+ {%- set overwrite_src_columns = datavault4dbt .extract_overwrite_columns (derived_columns) - %}
159160 {# - Getting Data types for derived columns with detection from source relation -#}
160161 {%- set derived_columns_with_datatypes = datavault4dbt .derived_columns_datatypes (derived_columns, source_relation) - %}
161162 {%- set derived_columns_with_datatypes_DICT = fromjson(derived_columns_with_datatypes) - %}
163+ {%- else - %}
164+ {%- set overwrite_src_columns = [] - %}
162165{%- endif - %}
163166{# - Select hashing algorithm -#}
164167
@@ -357,6 +360,7 @@ prejoined_columns AS (
357360derived_columns AS (
358361
359362 {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, derived_column_names) - %}
363+ {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, overwrite_src_columns) - %}
360364
361365 SELECT
362366 {% if final_columns_to_select | length > 0 - %}
Original file line number Diff line number Diff line change 160160 {{ log(' derived_columns_to select : ' ~ derived_columns_to_select, false) }}
161161
162162{%- if datavault4dbt .is_something (derived_columns) %}
163+ {%- set overwrite_src_columns = datavault4dbt .extract_overwrite_columns (derived_columns) - %}
163164 {# - Getting Data types for derived columns with detection from source relation -#}
164165 {%- set derived_columns_with_datatypes = datavault4dbt .derived_columns_datatypes (derived_columns, source_relation) - %}
165166 {%- set derived_columns_with_datatypes_DICT = fromjson(derived_columns_with_datatypes) - %}
167+ {%- else - %}
168+ {%- set overwrite_src_columns = [] - %}
166169{%- endif - %}
167170{# - Select hashing algorithm -#}
168171
@@ -364,6 +367,7 @@ prejoined_columns AS (
364367derived_columns AS (
365368
366369 {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, derived_column_names) - %}
370+ {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, overwrite_src_columns) - %}
367371
368372 SELECT
369373 {% if final_columns_to_select | length > 0 - %}
Original file line number Diff line number Diff line change 168168{%- endmacro - %}
169169
170170
171+ {%- macro extract_overwrite_columns(columns_dict= none) - %}
172+ {# - Returns all src_cols_required for derived columns where overwrite_src_cols=true.
173+ Used to drop the original source column from the derived_columns CTE SELECT list,
174+ so only the renamed alias survives (e .g . when renaming a column with special characters). - # }
175+
176+ {%- set ns = namespace(overwrite_columns = []) - %}
177+
178+ {%- if columns_dict is mapping - %}
179+ {%- for key, value in columns_dict .items () - %}
180+ {%- if value is mapping and value .get (' overwrite_src_cols' , false) and ' src_cols_required' in value - %}
181+ {%- if datavault4dbt .is_list (value[' src_cols_required' ]) - %}
182+ {%- set ns .overwrite_columns = ns .overwrite_columns + value[' src_cols_required' ] - %}
183+ {%- else - %}
184+ {%- do ns .overwrite_columns .append(value[' src_cols_required' ]) - %}
185+ {%- endif - %}
186+ {%- endif - %}
187+ {%- endfor - %}
188+ {%- endif - %}
189+
190+ {%- do return(ns .overwrite_columns ) - %}
191+
192+ {%- endmacro - %}
193+
194+
171195{%- macro process_hash_column_excludes(hash_columns= none, source_columns= none) - %}
172196
173197 {%- set processed_hash_columns = {} - %}
Original file line number Diff line number Diff line change 149149{%- set derived_columns_to_select = datavault4dbt .process_columns_to_select (source_and_derived_column_names, hashed_column_names) | unique | list - %}
150150
151151{%- if datavault4dbt .is_something (derived_columns) %}
152+ {%- set overwrite_src_columns = datavault4dbt .extract_overwrite_columns (derived_columns) - %}
152153 {# - Getting Data types for derived columns with detection from source relation -#}
153154 {%- set derived_columns_with_datatypes = datavault4dbt .derived_columns_datatypes (derived_columns, source_relation) - %}
154155 {%- set derived_columns_with_datatypes_DICT = fromjson(derived_columns_with_datatypes) - %}
156+ {%- else - %}
157+ {%- set overwrite_src_columns = [] - %}
155158{%- endif - %}
156159{# - Select hashing algorithm -#}
157160
@@ -363,6 +366,7 @@ derived_columns AS (
363366 {%- endif - %}
364367
365368 {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, exluded_derived_columns) - %}
369+ {%- set final_columns_to_select = datavault4dbt .process_columns_to_select (final_columns_to_select, overwrite_src_columns) - %}
366370
367371 SELECT
368372 {% if final_columns_to_select | length > 0 - %}
You can’t perform that action at this time.
0 commit comments