Skip to content

Commit

Permalink
Update table relation after exchange command (#230)
Browse files Browse the repository at this point in the history
Related to #226
  • Loading branch information
Somtom authored Apr 12, 2024
1 parent 6a6531a commit d94f93b
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
{% 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 %}
{% endif %}
{% do run_query(create_distributed_table(target_relation, target_relation_local)) or '' %}
{% do run_query(clickhouse__insert_into(target_relation, sql)) or '' %}
{{ drop_relation_if_exists(view_relation) }}
-- cleanup
Expand All @@ -85,7 +85,7 @@
{%- set cluster = cluster[1:-1] -%}
{%- set sharding = config.get('sharding_key') -%}

create table {{ relation }} {{ on_cluster_clause(relation) }} as {{ local_relation }}
create or replace table {{ relation }} {{ on_cluster_clause(relation) }} as {{ local_relation }}
ENGINE = Distributed('{{ cluster}}', '{{ relation.schema }}', '{{ local_relation.name }}'
{%- if sharding is not none and sharding.strip() != '' -%}
, {{ sharding }}
Expand All @@ -98,6 +98,7 @@
{% macro create_empty_table_from_relation(relation, source_relation) -%}
{%- set sql_header = config.get('sql_header', none) -%}
{%- set columns = adapter.get_columns_in_relation(source_relation) | list -%}


{%- set col_list = [] -%}
{% for col in columns %}
Expand All @@ -109,7 +110,7 @@
{{ on_cluster_clause(relation) }} (
{{col_list | join(', ')}}
)

{{ engine_clause() }}
{{ order_cols(label="order by") }}
{{ primary_key_clause(label="primary key") }}
Expand Down

0 comments on commit d94f93b

Please sign in to comment.