Skip to content

Commit

Permalink
improve control flow
Browse files Browse the repository at this point in the history
  • Loading branch information
dataders committed May 22, 2024
1 parent a9fef3b commit 76b5f4d
Showing 1 changed file with 9 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

{%- set old_relation = adapter.get_relation(database=database, schema=schema, identifier=identifier) -%}

{{ log('old_relation.is_table: ' ~ old_relation.is_table, info=True) }}
{{ log('old_relation.is_external_table: ' ~ old_relation.is_external_table, info=True) }}

{%- set exists_as_table = (old_relation is not none and old_relation.is_table) -%}
{%- set exists_as_view = (old_relation is not none and old_relation.is_view) -%}
{%- set exists_as_external_table = (old_relation is not none and old_relation.is_external_table) -%}
Expand All @@ -23,44 +20,31 @@
{{ run_hooks(pre_hooks, inside_transaction=True) }}

-- build model
{% set build_plan = "" %}

{% set create_or_replace = (old_relation is none or full_refresh_mode) %}
{{ log('create_or_replace: ' ~ create_or_replace, info=True) }}
{% set build_plan = [] %}

{% if old_relation is not none %}

{% endif %}

{% if exists_as_view %}
{{ exceptions.raise_compiler_error("Cannot make ExTab to '{}', it is already view".format(old_relation)) }}
{% elif exists_as_table %}
{{ exceptions.raise_compiler_error("Cannot make ExTab '{}', it is a already a table".format(old_relation)) }}
{% elif exists_as_external_table %}
{# {{ exceptions.raise_compiler_error("Cannot make ExTab '{}', it is a already a table".format(old_relation)) }} #}
{# {% elif exists_as_external_table %} #}
{% if full_refresh_mode %}
{% set build_plan = build_plan + create_external_table(target_relation, model.columns.values()) %}
{% set code = 'CREATE' %}
{% set build_plan = build_plan + [create_external_table(target_relation, model.columns.values())] %}
{% elif not full_refresh_mode %}
{% set build_plan = build_plan + refresh_external_table(source_node) %}
{% set code = 'REFRESH' %}
{% set build_plan = build_plan + refresh_external_table(target_relation) %}
{% endif %}
{% else %}
{% set code = 'CREATE' %}
{% set build_plan = build_plan + [
create_external_schema(source_node),
create_external_table(source_node)
create_external_table(target_relation, model.columns.values())
] %}
{% endif %}

{% set build_plan = create_external_table(target_relation, model.columns.values()) %}

{% set code = 'CREATE' if create_or_replace else 'REFRESH' %}

{{ log('XXX: build_plan: ' ~ build_plan, info=True) }}

{% call noop_statement('main', code, code) %}
{{ build_plan }};
{% endcall %}

{% set target_relation = old_relation.incorporate(type='external_table') %}

{% set should_revoke = should_revoke(old_relation, full_refresh_mode) %}
{% do apply_grants(target_relation, grant_config, should_revoke=should_revoke) %}

Expand Down

0 comments on commit 76b5f4d

Please sign in to comment.