Skip to content

Commit

Permalink
Updating dispatching methods to ensure dbt-synapse adapter can use ad…
Browse files Browse the repository at this point in the history
…apter dispatch methods
  • Loading branch information
prdpsvs committed May 21, 2024
1 parent 45dacbc commit e886a69
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{%- set full_refresh_mode = (should_full_refresh()) -%}
{% set target_relation = this.incorporate(type='table') %}
{%- set relations_list = fabric__get_relation_without_caching(target_relation) -%}
{%- set relations_list = get_relation_without_caching(target_relation) -%}

{%- set existing_relation = none %}
{% if (relations_list|length == 1) and (relations_list[0][2] == target_relation.schema)
Expand All @@ -14,9 +14,9 @@
{% set existing_relation = get_or_create_relation(relations_list[0][0], relations_list[0][2] , relations_list[0][1] , relations_list[0][3])[1] %}
{% endif %}

{{ log("Full refresh mode" ~ full_refresh_mode)}}
{# {{ log("Full refresh mode" ~ full_refresh_mode)}}
{{ log("existing relation : "~existing_relation ~ " type "~ existing_relation.type ~ " is view? "~existing_relation.is_view) }}
{{ log("target relation: " ~target_relation ~ " type "~ target_relation.type ~ " is view? "~target_relation.is_view) }}
{{ log("target relation: " ~target_relation ~ " type "~ target_relation.type ~ " is view? "~target_relation.is_view) }} #}

-- configs
{%- set unique_key = config.get('unique_key') -%}
Expand All @@ -31,7 +31,7 @@
{% if existing_relation is none %}

{%- call statement('main') -%}
{{ fabric__create_table_as(False, target_relation, sql)}}
{{ create_table_as(False, target_relation, sql)}}
{%- endcall -%}

{% elif existing_relation.is_view %}
Expand All @@ -40,19 +40,19 @@
{{ log("Dropping relation " ~ target_relation ~ " because it is a view and this model is a table.") }}
{{ drop_relation_if_exists(existing_relation) }}
{%- call statement('main') -%}
{{ fabric__create_table_as(False, target_relation, sql)}}
{{ create_table_as(False, target_relation, sql)}}
{%- endcall -%}

{% elif full_refresh_mode %}

{%- call statement('main') -%}
{{ fabric__create_table_as(False, target_relation, sql)}}
{{ create_table_as(False, target_relation, sql)}}
{%- endcall -%}

{% else %}

{%- call statement('create_tmp_relation') -%}
{{ fabric__create_table_as(True, temp_relation, sql)}}
{{ create_table_as(True, temp_relation, sql)}}
{%- endcall -%}
{% do adapter.expand_target_column_types(
from_relation=temp_relation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{%- set target_relation = this.incorporate(type='table') -%}

{% call statement('main') %}
{{ fabric__drop_relation_script(target_relation) }}
{{ drop_relation_if_exists(target_relation) }}
{{ create_or_replace_clone(target_relation, defer_relation) }}
{% endcall %}
{{ return({'relations': [target_relation]}) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
{% set tmp_relation = relation.incorporate(
path={"identifier": relation.identifier.replace("#", "") ~ '_temp_view'},
type='view')-%}
{% do run_query(fabric__drop_relation_script(tmp_relation)) %}
{% do run_query(drop_relation_if_exists(tmp_relation)) %}

{% set contract_config = config.get('contract') %}

{{ fabric__create_view_as(tmp_relation, sql) }}
{{ create_view_as(tmp_relation, sql) }}
{% if contract_config.enforced %}

CREATE TABLE [{{relation.database}}].[{{relation.schema}}].[{{relation.identifier}}]
Expand All @@ -27,6 +27,6 @@
EXEC('CREATE TABLE [{{relation.database}}].[{{relation.schema}}].[{{relation.identifier}}] AS (SELECT * FROM [{{tmp_relation.database}}].[{{tmp_relation.schema}}].[{{tmp_relation.identifier}}]);');
{% endif %}

{{ fabric__drop_relation_script(tmp_relation) }}
{{ drop_relation_if_exists(tmp_relation) }}

{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
{%- set target_relation = this.incorporate(type='view') -%}
{{log("Target Relation "~target_relation)}}

{%- set relation = fabric__get_relation_without_caching(this) %}
{%- set relation = get_relation_without_caching(this) %}
{% set existing_relation = none %}
{% if (relation|length == 1) %}
{% set existing_relation = get_or_create_relation(relation[0][0], relation[0][2] , relation[0][1] , relation[0][3])[1] %}
{% endif %}
{{log("Existing Relation "~existing_relation)}}
{# {{log("Existing Relation "~existing_relation)}} #}

{%- set backup_relation = none %}
{{log("Existing Relation type is "~ existing_relation.type)}}
{# {{log("Existing Relation type is "~ existing_relation.type)}} #}
{% if (existing_relation != none and existing_relation.type == "table") %}
{%- set backup_relation = make_backup_relation(target_relation, 'table') -%}
{% elif (existing_relation != none and existing_relation.type == "view") %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@

{% macro build_snapshot_staging_table(strategy, temp_snapshot_relation, target_relation) %}
{% set temp_relation = make_temp_relation(target_relation) %}
{% set select = fabric__snapshot_staging_table(strategy, temp_snapshot_relation, target_relation) %}
{% set select = snapshot_staging_table(strategy, temp_snapshot_relation, target_relation) %}
{% call statement('build_snapshot_staging_relation') %}
{{ create_table_as(True, temp_relation, select) }}
{% endcall %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,13 @@
insert_cols = quoted_source_columns
)
%}

{% endif %}

{% call statement('main') %}
{{ final_sql }}
{% endcall %}

fabric__drop_relation_script(temp_snapshot_relation)

{{ drop_relation_if_exists(temp_snapshot_relation) }}
{% set should_revoke = should_revoke(target_relation_exists, full_refresh_mode=False) %}
{% do apply_grants(target_relation, grant_config, should_revoke=should_revoke) %}

Expand All @@ -94,15 +92,13 @@
{% endif %}

{{ run_hooks(post_hooks, inside_transaction=True) }}

{{ adapter.commit() }}

{% if staging_table is defined %}
{% do post_snapshot(staging_table) %}
{% endif %}

{{ run_hooks(post_hooks, inside_transaction=False) }}

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

{% endmaterialization %}

0 comments on commit e886a69

Please sign in to comment.