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 cee50d7 commit 7e92daa
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions dbt/include/sqlserver/macros/materializations/test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,26 @@

{% 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 7e92daa

Please sign in to comment.