|
15 | 15 | {% do exceptions.raise_compiler_error('To use distributed materializations cluster setting in dbt profile must be set') %}
|
16 | 16 | {% endif %}
|
17 | 17 |
|
18 |
| - {% set existing_relation_local = existing_relation.incorporate(path={"identifier": this.identifier + local_suffix, "schema": local_db_prefix + this.schema}) if existing_relation is not none else none %} |
| 18 | + {% set existing_relation_local = load_cached_relation(this.incorporate(path={"identifier": this.identifier + local_suffix, "schema": local_db_prefix + this.schema})) %} |
19 | 19 | {% set target_relation_local = target_relation.incorporate(path={"identifier": this.identifier + local_suffix, "schema": local_db_prefix + this.schema}) if target_relation is not none else none %}
|
20 | 20 |
|
21 | 21 | {%- set unique_key = config.get('unique_key') -%}
|
|
55 | 55 | {{ create_view_as(view_relation, sql) }}
|
56 | 56 | {% endcall %}
|
57 | 57 |
|
58 |
| - {% if existing_relation is none %} |
59 |
| - -- No existing table, simply create a new one |
| 58 | + {% if existing_relation_local is none %} |
| 59 | + -- No existing local table, recreate local and distributed tables |
60 | 60 | {{ create_distributed_local_table(target_relation, target_relation_local, view_relation, sql) }}
|
61 | 61 |
|
62 | 62 | {% elif full_refresh_mode %}
|
|
74 | 74 | {% endcall %}
|
75 | 75 |
|
76 | 76 | {% else %}
|
| 77 | + {% if existing_relation is none %} |
| 78 | + {% do run_query(create_distributed_table(target_relation, target_relation_local)) %} |
| 79 | + {% set existing_relation = target_relation %} |
| 80 | + {% endif %} |
| 81 | + |
77 | 82 | {% set incremental_strategy = adapter.calculate_incremental_strategy(config.get('incremental_strategy')) %}
|
78 | 83 | {% set incremental_predicates = config.get('predicates', none) or config.get('incremental_predicates', none) %}
|
79 | 84 | {%- if on_schema_change != 'ignore' %}
|
|
0 commit comments