Skip to content

Commit

Permalink
fix: distributed_table materialization issue (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
zli06160 authored Aug 22, 2023
1 parent 4b8a202 commit 9c8139f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dbt/include/clickhouse/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@

{% macro exchange_tables_atomic(old_relation, target_relation, obj_types='TABLES') %}

{%- if adapter.get_clickhouse_cluster_name() is not none and obj_types == 'TABLES' %}
{%- if adapter.get_clickhouse_cluster_name() is not none and obj_types == 'TABLES' and 'Replicated' in engine_clause() %}
{% do run_query("SYSTEM SYNC REPLICA " + on_cluster_clause() + target_relation.schema + '.' + target_relation.identifier) %}
{%- endif %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@
{% elif existing_relation.can_exchange %}
-- We can do an atomic exchange, so no need for an intermediate
{% call statement('main') -%}
{% do run_query(create_empty_table_from_relation(backup_relation, view_relation)) or '' %}
{{ create_empty_table_from_relation(backup_relation, view_relation) }}
{%- endcall %}
{% do exchange_tables_atomic(backup_relation, existing_relation) %}
{% do exchange_tables_atomic(backup_relation, existing_relation_local) %}
{% else %}
{% do run_query(create_empty_table_from_relation(intermediate_relation, view_relation)) or '' %}
{{ adapter.rename_relation(existing_relation_local, backup_relation) }}
{{ adapter.rename_relation(intermediate_relation, target_relation_local) }}
{{ create_distributed_table(target_relation, target_relation_local) }}
{% endif %}
{% do run_query(clickhouse__insert_into(target_relation, sql)) or '' %}
{{ drop_relation_if_exists(view_relation) }}
Expand Down

0 comments on commit 9c8139f

Please sign in to comment.