Skip to content

Commit

Permalink
Extract on_table_exists logic to separate macro, so it could be used …
Browse files Browse the repository at this point in the history
…in other materializations
  • Loading branch information
damian3031 committed Apr 30, 2024
1 parent 67bfd79 commit 2931724
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions dbt/include/trino/macros/materializations/table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@
-- grab current tables grants config for comparision later on
{% set grant_config = config.get('grants') %}

{#-- Create table with given `on_table_exists` mode #}
{% do on_table_exists_logic(on_table_exists, existing_relation, intermediate_relation, backup_relation, target_relation) %}

{% do persist_docs(target_relation, model) %}

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

{{ run_hooks(post_hooks) }}

{{ return({'relations': [target_relation]}) }}
{% endmaterialization %}


{% macro on_table_exists_logic(on_table_exists, existing_relation, intermediate_relation, backup_relation, target_relation) -%}
{#-- Create table with given `on_table_exists` mode #}
{% if on_table_exists == 'rename' %}
{#-- build modeldock #}
{% call statement('main') -%}
Expand Down Expand Up @@ -64,13 +80,4 @@
{{ create_table_as(False, target_relation, sql, True) }}
{%- endcall %}
{% endif %}

{% do persist_docs(target_relation, model) %}

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

{{ run_hooks(post_hooks) }}

{{ return({'relations': [target_relation]}) }}
{% endmaterialization %}
{% endmacro %}

0 comments on commit 2931724

Please sign in to comment.