Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: distributed_table materialization issue #184

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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