Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dbt-msft/dbt-synapse-serverless
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: nvinhphuc/dbt-synapse-serverless
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Apr 1, 2022

  1. Create materialization for CETAS

    pnguyen committed Apr 1, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    1b1a232 View commit details

Commits on Apr 6, 2022

  1. change dependencies

    pnguyen committed Apr 6, 2022
    Copy the full SHA
    e21ef24 View commit details
20 changes: 20 additions & 0 deletions dbt/include/synapseserverless/macros/adapters/relation.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% macro synapseserverless__drop_relation(relation) -%}
{% call statement('drop_relation', auto_begin=False) -%}
{{ synapseserverless__drop_relation_script(relation) }}
{%- endcall %}
{% endmacro %}

{% macro synapseserverless__drop_relation_script(relation) -%}
{% if relation.type == 'view' -%}
{% set object_id_type = 'V' %}
{% set relation_type = 'view' %}
{% elif relation.type == 'external'%}
{% set object_id_type = 'U' %}
{% set relation_type = 'external table' %}
{%- else -%} invalid target name
{% endif %}
if object_id ('{{ relation.include(database=False) }}','{{ object_id_type }}') is not null
begin
drop {{ relation_type }} {{ relation.include(database=False) }}
end
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{% macro get_create_external_table_as_sql(temporary, relation, sql) -%}
{{ adapter.dispatch('get_create_external_table_as_sql', 'dbt')(temporary, relation, sql) }}
{%- endmacro %}

{% macro default__get_create_external_table_as_sql(temporary, relation, sql) -%}
{{ return(create_external_table_as(temporary, relation, sql)) }}
{% endmacro %}


{% macro create_external_table_as(temporary, relation, sql) -%}
{{ adapter.dispatch('create_external_table_as', 'dbt')(temporary, relation, sql) }}
{%- endmacro %}

{% macro default__create_external_table_as(temporary, relation, sql) -%}
{%- set sql_header = config.get('sql_header', none) -%}

{{ sql_header if sql_header is not none }}

create {% if temporary: -%}temporary{%- endif %} table
{{ relation.include(database=(not temporary), schema=(not temporary)) }}
as (
{{ sql }}
);
{%- endmacro %}

{% macro synapseserverless__create_external_table_as(temporary, relation, sql) -%}
{%- set location = config.get('location', default="") -%}
{%- set data_source = config.get('data_source', default="") -%}
{%- set file_format = config.get('file_format', default="") -%}
{% set tmp_relation = relation.incorporate(
path={"identifier": relation.identifier.replace("#", "") ~ '_temp_view'},
type='view')-%}
{%- set temp_view_sql = sql.replace("'", "''") -%}

{{ synapseserverless__drop_relation_script(tmp_relation) }}

{{ synapseserverless__drop_relation_script(relation) }}

EXEC('create view {{ tmp_relation.schema }}.{{ tmp_relation.identifier }} as
{{ temp_view_sql }}
');

CREATE EXTERNAL TABLE {{ relation.include(database=False) }}
WITH(
LOCATION = {{ "\'" + location + "\'" }},
DATA_SOURCE = {{data_source}},
FILE_FORMAT = {{file_format}}
)
AS (SELECT * FROM {{ tmp_relation.schema }}.{{ tmp_relation.identifier }})

{{ synapseserverless__drop_relation_script(tmp_relation) }}

{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% materialization external, default %}
{%- set identifier = model['alias'] -%}
{%- set tmp_identifier = model['name'] + '__dbt_tmp' -%}
{%- set backup_identifier = model['name'] + '__dbt_backup' -%}

{%- set target_relation = api.Relation.create(identifier=identifier,
schema=schema,
database=database,
type='external') -%}

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

-- `BEGIN` happens here:
{{ run_hooks(pre_hooks, inside_transaction=True) }}

-- build model
{% call statement('main') -%}
{{ get_create_external_table_as_sql(False, target_relation, sql) }}
{%- endcall %}

-- cleanup

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

{% do persist_docs(target_relation, model) %}

-- `COMMIT` happens here
{{ adapter.commit() }}

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

{{ return({'relations': [target_relation]}) }}
{% endmaterialization %}
5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -51,8 +51,5 @@ def _dbt_synapseserverless_version():
author_email="swanson.anders@gmail.com",
url="https://github.com/dbt-msft/dbt-synapse-serverless",
packages=find_packages(),
include_package_data=True,
install_requires=[
"dbt-synapse~=0.20.0"
]
include_package_data=True
)