Skip to content

Commit

Permalink
always store results; but drop them unless specified to store
Browse files Browse the repository at this point in the history
  • Loading branch information
dataders committed Nov 6, 2021
1 parent cb9e4df commit 52222e0
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions dbt/include/sqlserver/macros/materializations/test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,28 @@

{%- materialization test, adapter='sqlserver' -%}

{% set relations = [] %}
{% set relations = [] %}

{% if should_store_failures() %}
{% 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') -%} %}

{% 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) %}
{% endif %}

{% call statement(auto_begin=True) %}
{{ create_table_as(False, target_relation, sql) }}
{% endcall %}

{% do relations.append(target_relation) %}
{% if old_relation %}
{% do adapter.drop_relation(old_relation) %}
{% endif %}

{% set main_sql %}
select *
from {{ target_relation }}
{% endset %}

{{ adapter.commit() }}
{% call statement(auto_begin=True) %}
{{ create_table_as(False, target_relation, sql) }}
{% endcall %}

{% set main_sql %}
select *
from {{ target_relation }}
{% endset %}

{% else %}

{% set main_sql = sql %}
{{ adapter.commit() }}

{% endif %}

{% set limit = config.get('limit') %}
{% set fail_calc = config.get('fail_calc') %}
Expand All @@ -55,6 +46,12 @@
{{ 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}) }}

Expand Down

0 comments on commit 52222e0

Please sign in to comment.