-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from dbt-msft/synapse_rdbms_type
enable Azure SQL's "elastic query"-style external tables (RDBMS / cross-database)
- Loading branch information
Showing
10 changed files
with
139 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 63 additions & 27 deletions
90
integration_tests/macros/plugins/sqlserver/prep_external.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,71 @@ | ||
{% macro sqlserver__prep_external() %} | ||
|
||
{% set external_data_source = target.schema ~ '.dbt_external_tables_testing' %} | ||
|
||
{% set create_external_data_source %} | ||
IF NOT EXISTS ( SELECT * FROM sys.external_data_sources WHERE name = '{{external_data_source}}' ) | ||
|
||
CREATE EXTERNAL DATA SOURCE [{{external_data_source}}] WITH ( | ||
TYPE = HADOOP, | ||
LOCATION = 'wasbs://[email protected]' | ||
) | ||
{% endset %} | ||
|
||
{% set external_file_format = target.schema ~ '.dbt_external_ff_testing' %} | ||
|
||
{% set create_external_file_format %} | ||
IF NOT EXISTS ( SELECT * FROM sys.external_file_formats WHERE name = '{{external_file_format}}' ) | ||
|
||
CREATE EXTERNAL FILE FORMAT [{{external_file_format}}] | ||
WITH ( | ||
FORMAT_TYPE = DELIMITEDTEXT, | ||
FORMAT_OPTIONS ( | ||
FIELD_TERMINATOR = N',', | ||
FIRST_ROW = 2, | ||
USE_TYPE_DEFAULT = True | ||
|
||
{% if target.name == "synapse"%} | ||
|
||
{% set create_external_data_source %} | ||
IF NOT EXISTS ( SELECT * FROM sys.external_data_sources WHERE name = '{{external_data_source}}' ) | ||
|
||
CREATE EXTERNAL DATA SOURCE [{{external_data_source}}] WITH ( | ||
TYPE = HADOOP, | ||
LOCATION = 'wasbs://[email protected]' | ||
) | ||
) | ||
{% endset %} | ||
{% endset %} | ||
|
||
{% set external_file_format = target.schema ~ '.dbt_external_ff_testing' %} | ||
|
||
{% set create_external_file_format %} | ||
IF NOT EXISTS ( SELECT * FROM sys.external_file_formats WHERE name = '{{external_file_format}}' ) | ||
|
||
CREATE EXTERNAL FILE FORMAT [{{external_file_format}}] | ||
WITH ( | ||
FORMAT_TYPE = DELIMITEDTEXT, | ||
FORMAT_OPTIONS ( | ||
FIELD_TERMINATOR = N',', | ||
FIRST_ROW = 2, | ||
USE_TYPE_DEFAULT = True | ||
) | ||
) | ||
{% endset %} | ||
|
||
{% elif target.name == "azuresql" %} | ||
|
||
{% set cred_name = 'synapse_reader' %} | ||
|
||
{% set create_database_scoped_credential %} | ||
IF NOT EXISTS ( SELECT * FROM sys.database_scoped_credentials WHERE name = '{{ cred_name }}') | ||
CREATE DATABASE SCOPED CREDENTIAL [{{ cred_name }}] WITH | ||
IDENTITY = '{{ env_var("DBT_SYNAPSE_UID") }}', | ||
SECRET = '{{ env_var("DBT_SYNAPSE_PWD") }}' | ||
|
||
{% endset %} | ||
|
||
{% set create_external_data_source %} | ||
IF NOT EXISTS ( SELECT * FROM sys.external_data_sources WHERE name = '{{external_data_source}}' ) | ||
|
||
CREATE EXTERNAL DATA SOURCE [{{external_data_source}}] WITH ( | ||
TYPE = RDBMS, | ||
LOCATION = '{{ env_var("DBT_SYNAPSE_SERVER") }}', | ||
DATABASE_NAME = '{{ env_var("DBT_SYNAPSE_DB") }}', | ||
CREDENTIAL = [{{ cred_name }}] | ||
) | ||
{% endset %} | ||
|
||
{%- endif %} | ||
|
||
|
||
{% if target.name == "azuresql" -%} | ||
{% do log('Creating database scoped credential ' ~ cred_name, info = true) %} | ||
{% do run_query(create_database_scoped_credential) %} | ||
{%- endif %} | ||
|
||
{% do log('Creating external data source ' ~ external_data_source, info = true) %} | ||
{% do run_query(create_external_data_source) %} | ||
{% do log('Creating external file format ' ~ external_file_format, info = true) %} | ||
{% do run_query(create_external_file_format) %} | ||
|
||
|
||
{% if target.name == "synapse" -%} | ||
{% do log('Creating external file format ' ~ external_file_format, info = true) %} | ||
{% do run_query(create_external_file_format) %} | ||
{%- endif %} | ||
|
||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters