|
2 | 2 |
|
3 | 3 | {%- set identifier = model['alias'] -%} |
4 | 4 | {%- set model_config = model['config'] -%} |
5 | | - {% set incremental_strategy = adapter.get(model_config, 'incremental_strategy', False) %} |
6 | | - {% set sync = adapter.get(model_config, 'sync', False) %} |
7 | | - {% set options = adapter.get(model_config, 'options', {}) %} |
8 | | - {% set source = adapter.get(model_config, 'source') %} |
9 | | - {% set target_type = adapter.get(model_config, 'target_type', 'datalake').lower() %} |
10 | | - {% set target_schema = adapter.get(model_config, 'target_schema', schema) %} |
11 | | - {% set delete_condition = adapter.get(model_config, 'delete_condition', False) %} |
12 | | - {% set partition_by = adapter.get(model_config, 'partition_by', []) %} |
13 | | - {% set primary_key = adapter.get(model_config, 'primary_key', []) %} |
14 | | - {% set map_columns_by_name = adapter.get(model_config, 'map_columns_by_name', False) %} |
15 | | - {% set job_identifier = identifier + '_job' %} |
| 5 | + {%- set incremental_strategy = adapter.get(model_config, 'incremental_strategy', False) -%} |
| 6 | + {%- set sync = adapter.get(model_config, 'sync', False) -%} |
| 7 | + {%- set options = adapter.get(model_config, 'options', {}) -%} |
| 8 | + {%- set source = adapter.get(model_config, 'source') -%} |
| 9 | + {%- set target_type = adapter.get(model_config, 'target_type', 'datalake').lower() -%} |
| 10 | + {%- set target_schema = adapter.get(model_config, 'target_schema', schema) -%} |
| 11 | + {%- set target_table_alias = adapter.get(model_config, 'target_table_alias', identifier) -%} |
| 12 | + {%- set delete_condition = adapter.get(model_config, 'delete_condition', False) -%} |
| 13 | + {%- set partition_by = adapter.get(model_config, 'partition_by', []) -%} |
| 14 | + {%- set primary_key = adapter.get(model_config, 'primary_key', []) -%} |
| 15 | + {%- set map_columns_by_name = adapter.get(model_config, 'map_columns_by_name', False) -%} |
| 16 | + {%- set job_identifier = identifier + '_job' %} |
16 | 17 |
|
17 | 18 | {%- set old_relation = adapter.get_relation(identifier=job_identifier, |
18 | 19 | schema=schema, |
|
29 | 30 |
|
30 | 31 |
|
31 | 32 | {% if target_type == 'datalake' %} |
32 | | - {%- set table_relation = api.Relation.create(identifier=identifier, |
| 33 | + {%- set table_relation = api.Relation.create(identifier=target_table_alias, |
33 | 34 | schema=schema, |
34 | 35 | database=database, |
35 | 36 | type='table') -%} |
|
39 | 40 | {%- endcall -%} |
40 | 41 | {%- else -%} |
41 | 42 | {% set target_connection = adapter.require(model_config, 'target_connection') %} |
42 | | - {%- set into_relation = target_connection + '.' + target_schema + '.' + identifier -%} |
| 43 | + {%- set into_relation = target_connection + '.' + target_schema + '.' + target_table_alias -%} |
43 | 44 | {%- endif %} |
44 | 45 |
|
45 | | - {% if old_relation %} |
46 | | - {% call statement('main') -%} |
| 46 | + {%- if old_relation -%} |
| 47 | + {%- call statement('main') -%} |
47 | 48 | {{ get_alter_job_sql(job_identifier, options, incremental_strategy, source) }} |
48 | 49 | {%- endcall %} |
49 | | - {% else %} |
50 | | - {% call statement('main') -%} |
51 | | - {% if incremental_strategy == 'merge' %} |
| 50 | + {%- else -%} |
| 51 | + {%- call statement('main') -%} |
| 52 | + {%- if incremental_strategy == 'merge' -%} |
52 | 53 | {{ get_create_merge_job_sql(job_identifier, into_relation, sync, |
53 | 54 | options, primary_key, delete_condition, |
54 | 55 | target_type) }} |
55 | | - {% elif incremental_strategy == 'insert' %} |
| 56 | + {%- elif incremental_strategy == 'insert' -%} |
56 | 57 | {{ get_create_insert_job_sql(job_identifier, |
57 | 58 | into_relation, sync, options, |
58 | 59 | map_columns_by_name, target_type) }} |
59 | 60 |
|
60 | | - {% else %} |
| 61 | + {%- else -%} |
61 | 62 | {{ get_create_copy_job_sql(job_identifier, sql, |
62 | 63 | into_relation, sync, options, source, |
63 | 64 | target_type) }} |
64 | 65 |
|
65 | | - {% endif %} |
66 | | - {%- endcall %} |
67 | | - {%- endif %} |
| 66 | + {%- endif -%} |
| 67 | + {%- endcall -%} |
| 68 | + {%- endif -%} |
68 | 69 |
|
69 | | - {% do persist_docs(target_relation, model) %} |
70 | | - {% do persist_docs(table_relation, model) %} |
| 70 | + {%- do persist_docs(target_relation, model) -%} |
| 71 | + {%- do persist_docs(table_relation, model) -%} |
71 | 72 |
|
72 | 73 | {{ run_hooks(post_hooks, inside_transaction=False) }} |
73 | 74 | {{ run_hooks(post_hooks, inside_transaction=True) }} |
74 | 75 |
|
75 | | - {% if target_type == 'datalake' %} |
| 76 | + {%- if target_type == 'datalake' -%} |
76 | 77 | {{ return({'relations': [target_relation, table_relation]}) }} |
77 | | - {% else %} |
| 78 | + {%- else -%} |
78 | 79 | {{ return({'relations': [target_relation]}) }} |
79 | | - {%- endif %} |
80 | | -{% endmaterialization %} |
| 80 | + {%- endif -%} |
| 81 | +{%- endmaterialization -%} |
0 commit comments