-
Notifications
You must be signed in to change notification settings - Fork 35
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 #74 from dbt-msft/hotfix-duplicate-test-mat
re-implement sqlserver test materialization
- Loading branch information
Showing
3 changed files
with
61 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version = '1.0.0' | ||
version = '1.0.1' |
48 changes: 48 additions & 0 deletions
48
dbt/include/synapse/macros/materializations/tests/test.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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{%- materialization test, adapter='synapse' -%} | ||
|
||
{% set relations = [] %} | ||
|
||
{% set identifier = model['alias'] %} | ||
{% set old_relation = adapter.get_relation(database=database, schema=schema, identifier=identifier) %} | ||
{% set target_relation = api.Relation.create( | ||
identifier=identifier, schema=schema, database=database, type='table') -%} %} | ||
|
||
|
||
{% if old_relation %} | ||
{% do adapter.drop_relation(old_relation) %} | ||
{% elif not old_relation %} | ||
{% do adapter.create_schema(target_relation) %} | ||
{% endif %} | ||
|
||
{% call statement(auto_begin=True) %} | ||
{{ create_table_as(False, target_relation, sql) }} | ||
{% endcall %} | ||
|
||
{% set main_sql %} | ||
select * | ||
from {{ target_relation }} | ||
{% endset %} | ||
|
||
{{ adapter.commit() }} | ||
|
||
|
||
{% set limit = config.get('limit') %} | ||
{% set fail_calc = config.get('fail_calc') %} | ||
{% set warn_if = config.get('warn_if') %} | ||
{% set error_if = config.get('error_if') %} | ||
|
||
{% call statement('main', fetch_result=True) -%} | ||
|
||
{{ get_test_sql(main_sql, fail_calc, warn_if, error_if, limit)}} | ||
|
||
{%- endcall %} | ||
|
||
{% if should_store_failures() %} | ||
{% do relations.append(target_relation) %} | ||
{% elif not should_store_failures() %} | ||
{% do adapter.drop_relation(target_relation) %} | ||
{% endif %} | ||
|
||
{{ return({'relations': relations}) }} | ||
|
||
{%- endmaterialization -%} |