Skip to content

Commit 3d67aa9

Browse files
authored
Merge pull request #363 from canbekley/fix/drop-local-table-issue
don't drop local tables when there is no distributed table
2 parents c36c49f + d40abf4 commit 3d67aa9

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ The index config should be added to the model config. for instance:
5757
### Bug Fixes
5858
* Before this version, `split_part` macro used to add an extra quotation. that was fixed in ([#338](https://github.com/ClickHouse/dbt-clickhouse/pull/338))
5959

60+
### Bug Fixes
61+
* Existing local tables are no longer dropped/recreated in case of missing distributed tables in `distributed_incremental` materialization mode. ([#363](https://github.com/ClickHouse/dbt-clickhouse/pull/363))
62+
6063
### Release [1.8.4], 2024-09-17
6164
### Improvement
6265
* The S3 help macro now support a `role_arn` parameter as an alternative way to provide authentication for S3 based models. Thanks to

dbt/include/clickhouse/macros/materializations/incremental/distributed_incremental.sql

+8-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
{% do exceptions.raise_compiler_error('To use distributed materializations cluster setting in dbt profile must be set') %}
1616
{% endif %}
1717

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})) %}
1919
{% 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 %}
2020

2121
{%- set unique_key = config.get('unique_key') -%}
@@ -55,8 +55,8 @@
5555
{{ create_view_as(view_relation, sql) }}
5656
{% endcall %}
5757

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
6060
{{ create_distributed_local_table(target_relation, target_relation_local, view_relation, sql) }}
6161

6262
{% elif full_refresh_mode %}
@@ -74,6 +74,11 @@
7474
{% endcall %}
7575

7676
{% 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+
7782
{% set incremental_strategy = adapter.calculate_incremental_strategy(config.get('incremental_strategy')) %}
7883
{% set incremental_predicates = config.get('predicates', none) or config.get('incremental_predicates', none) %}
7984
{%- if on_schema_change != 'ignore' %}

0 commit comments

Comments
 (0)