Skip to content

Commit

Permalink
refactor: macro to set table relation schema, apply to old
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrebzl committed May 29, 2024
1 parent 22ccf57 commit 9123190
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 10 additions & 0 deletions dbt/include/athena/macros/adapters/relation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@
{%- endcall %}
{%- endmacro %}

{% macro set_table_relation_schema(relation, schema) %}
{%- if temp_schema is not none -%}
{%- set relation = relation.incorporate(path={
"schema": schema
}) -%}
{%- do create_schema(relation) -%}
{% endif %}
{{ return(relation) }}
{% endmacro %}

{% macro make_temp_relation(base_relation, suffix='__dbt_tmp', temp_schema=none) %}
{%- set temp_identifier = base_relation.identifier ~ suffix -%}
{%- set temp_relation = base_relation.incorporate(path={"identifier": temp_identifier}) -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
{%- set old_tmp_relation = adapter.get_relation(identifier=identifier ~ '__ha',
schema=schema,
database=database) -%}
{%- if temp_schema is not none and old_tmp_relation is not none-%}
{%- set old_tmp_relation = set_table_relation_schema(relation=old_tmp_relation, schema=temp_schema) -%}
{%- endif -%}
{%- set old_bkp_relation = adapter.get_relation(identifier=identifier ~ '__bkp',
schema=schema,
database=database) -%}
Expand All @@ -33,10 +36,7 @@
s3_path_table_part=target_relation.identifier,
type='table') -%}
{%- if temp_schema is not none -%}
{%- set tmp_relation = tmp_relation.incorporate(path={
"schema": temp_schema
}) -%}
{%- do create_schema(tmp_relation) -%}
{%- set tmp_relation = set_table_relation_schema(relation=tmp_relation, schema=temp_schema) -%}
{%- endif -%}

{%- if (
Expand Down

0 comments on commit 9123190

Please sign in to comment.