Skip to content

Commit 6b92392

Browse files
authored
Merge pull request #264 from microsoft/colin-rogers-dbt-patch-2
Create test.sql materialization
2 parents 18ed86c + 69020db commit 6b92392

File tree

1 file changed

+60
-0
lines changed
  • dbt/include/synapse/macros/materializations/tests

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{%- materialization test, adapter='synapse' -%}
2+
3+
{% set relations = [] %}
4+
5+
{% if should_store_failures() %}
6+
7+
{% set identifier = model['alias'] %}
8+
{% set old_relation = adapter.get_relation(database=database, schema=schema, identifier=identifier) %}
9+
10+
{% set store_failures_as = config.get('store_failures_as') %}
11+
-- if `--store-failures` is invoked via command line and `store_failures_as` is not set,
12+
-- config.get('store_failures_as', 'table') returns None, not 'table'
13+
{% if store_failures_as == none %}{% set store_failures_as = 'table' %}{% endif %}
14+
{% if store_failures_as not in ['table', 'view'] %}
15+
{{ exceptions.raise_compiler_error(
16+
"'" ~ store_failures_as ~ "' is not a valid value for `store_failures_as`. "
17+
"Accepted values are: ['ephemeral', 'table', 'view']"
18+
) }}
19+
{% endif %}
20+
21+
{% set target_relation = api.Relation.create(
22+
identifier=identifier, schema=schema, database=database, type=store_failures_as) -%} %}
23+
24+
{% if old_relation %}
25+
{% do adapter.drop_relation(old_relation) %}
26+
{% endif %}
27+
28+
{% call statement(auto_begin=True) %}
29+
{{ get_create_sql(target_relation, sql) }}
30+
{% endcall %}
31+
32+
{% do relations.append(target_relation) %}
33+
34+
{% set main_sql %}
35+
select *
36+
from {{ target_relation }}
37+
{% endset %}
38+
39+
{{ adapter.commit() }}
40+
41+
{% else %}
42+
43+
{% set main_sql = sql %}
44+
45+
{% endif %}
46+
47+
{% set limit = config.get('limit') %}
48+
{% set fail_calc = config.get('fail_calc') %}
49+
{% set warn_if = config.get('warn_if') %}
50+
{% set error_if = config.get('error_if') %}
51+
52+
{% call statement('main', fetch_result=True) -%}
53+
54+
{{ get_test_sql(main_sql, fail_calc, warn_if, error_if, limit)}}
55+
56+
{%- endcall %}
57+
58+
{{ return({'relations': relations}) }}
59+
60+
{%- endmaterialization -%}

0 commit comments

Comments
 (0)