|
150 | 150 | {% do return(get_incremental_merge_sql(arg_dict)) %} |
151 | 151 | {% endmacro %} |
152 | 152 |
|
| 153 | +
|
| 154 | +{% macro oracle__get_delete_sql_for_delete_insert_strategy(target, source, unique_key, incremental_predicates) %} |
| 155 | + {%- if unique_key -%} |
| 156 | + {%- set unique_key_result = oracle_check_and_quote_unique_key_for_incremental_merge(unique_key, incremental_predicates) -%} |
| 157 | + {%- set unique_key_list = unique_key_result['unique_key_list'] -%} |
| 158 | + DELETE FROM {{ target }} DBT_INTERNAL_DEST |
| 159 | + WHERE ({% for key in unique_key_list %} |
| 160 | + DBT_INTERNAL_DEST.{{ key }} {{ ", " if not loop.last}} |
| 161 | + {% endfor %}) |
| 162 | + IN (SELECT {% for key in unique_key_list %} |
| 163 | + DBT_INTERNAL_SOURCE.{{ key }} {{ ", " if not loop.last}} |
| 164 | + {% endfor %} FROM {{source}} DBT_INTERNAL_SOURCE) |
| 165 | + {%- if incremental_predicates -%} |
| 166 | + {% for predicate in incremental_predicates %} |
| 167 | + AND {{ predicate }} |
| 168 | + {% endfor %} |
| 169 | + {%- endif -%} |
| 170 | + {%- elif incremental_predicates -%} |
| 171 | + DELETE FROM {{ target }} DBT_INTERNAL_DEST |
| 172 | + WHERE {%- for predicate in incremental_predicates -%} |
| 173 | + {{ "AND" if not loop.first}} {{ predicate }} |
| 174 | + {%- endfor -%} |
| 175 | + {%- endif -%} |
| 176 | +{% endmacro %} |
| 177 | +
|
| 178 | +
|
153 | 179 | {% macro oracle__get_incremental_delete_insert_sql(args_dict) %} |
154 | 180 | {%- set parallel = config.get('parallel', none) -%} |
155 | 181 | {%- set dest_columns = args_dict["dest_columns"] -%} |
|
158 | 184 | {%- set unique_key = args_dict["unique_key"] -%} |
159 | 185 | {%- set dest_column_names = dest_columns | map(attribute='name') | list -%} |
160 | 186 | {%- set dest_cols_csv = get_quoted_column_csv(model, dest_column_names) -%} |
161 | | - {%- set merge_update_columns = config.get('merge_update_columns') -%} |
162 | | - {%- set merge_exclude_columns = config.get('merge_exclude_columns') -%} |
163 | 187 | {%- set incremental_predicates = args_dict["incremental_predicates"] -%} |
164 | | - {%- set update_columns = get_merge_update_columns(merge_update_columns, merge_exclude_columns, dest_columns) -%} |
165 | | - {%- if unique_key -%} |
166 | | - {%- set unique_key_result = oracle_check_and_quote_unique_key_for_incremental_merge(unique_key, incremental_predicates) -%} |
167 | | - {%- set unique_key_list = unique_key_result['unique_key_list'] -%} |
168 | | - {%- set unique_key_merge_predicates = unique_key_result['unique_key_merge_predicates'] -%} |
| 188 | + {%- if unique_key or incremental_predicates -%} |
169 | 189 | BEGIN |
170 | | - EXECUTE IMMEDIATE 'merge {% if parallel %} /*+parallel({{ parallel }})*/ {% endif %} into {{ target_relation }} DBT_INTERNAL_DEST |
171 | | - using {{ temp_relation }} DBT_INTERNAL_SOURCE |
172 | | - on ({{ unique_key_merge_predicates | join(' AND ') }}) |
173 | | - when matched then |
174 | | - update set |
175 | | - {% for col in update_columns if (col.upper() not in unique_key_list and col not in unique_key_list) -%} |
176 | | - DBT_INTERNAL_DEST.{{ col }} = DBT_INTERNAL_SOURCE.{{ col }}{% if not loop.last %}, {% endif %} |
177 | | - {% endfor -%} |
178 | | - DELETE WHERE 1=1'; |
| 190 | + EXECUTE IMMEDIATE '{{ oracle__get_delete_sql_for_delete_insert_strategy(target_relation, temp_relation, unique_key, incremental_predicates) }}'; |
179 | 191 | EXECUTE IMMEDIATE 'insert {% if parallel %} /*+parallel({{ parallel }})*/ {% endif %} into {{ target_relation }} ({{ dest_cols_csv }})( |
180 | 192 | select {{ dest_cols_csv }} |
181 | 193 | from {{ temp_relation }})'; |
182 | 194 | END; |
183 | 195 | {%- else -%} |
184 | | - insert {% if parallel %} /*+parallel({{ parallel }})*/ {% endif %} into {{ target_relation }} ({{ dest_cols_csv }}) |
| 196 | + insert {%- if parallel -%} /*+parallel({{ parallel }})*/ {%- endif -%} into {{ target_relation }} ({{ dest_cols_csv }}) |
185 | 197 | ( |
186 | 198 | select {{ dest_cols_csv }} |
187 | 199 | from {{ temp_relation }} |
|
0 commit comments