-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathtests.sql
More file actions
29 lines (24 loc) · 898 Bytes
/
tests.sql
File metadata and controls
29 lines (24 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{% macro sqlserver__get_test_sql(main_sql, fail_calc, warn_if, error_if, limit) -%}
-- Create target schema if it does not
USE [{{ target.database }}];
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = '{{ target.schema }}')
BEGIN
EXEC('CREATE SCHEMA "{{ target.schema }}"')
END
{% set testview %}
"{{ target.schema }}"."testview_{{ range(1300, 19000) | random }}"
{% endset %}
{% set sql = main_sql.replace("'", "''")%}
EXEC('create view {{testview}} as {{ sql }};')
select
{{ "top (" ~ limit ~ ')' if limit != none }}
{{ fail_calc }} as failures,
case when {{ fail_calc }} {{ warn_if }}
then 'true' else 'false' end as should_warn,
case when {{ fail_calc }} {{ error_if }}
then 'true' else 'false' end as should_error
from (
select * from {{testview}}
) dbt_internal_test;
EXEC('drop view {{testview}};')
{%- endmacro %}