|
7 | 7 | EXEC('CREATE SCHEMA [{{ target.schema }}]') |
8 | 8 | END |
9 | 9 |
|
10 | | - {% set with_statement_pattern = 'with .+ as\s*\(' %} |
11 | | - {% set re = modules.re %} |
12 | | - {% set is_match = re.search(with_statement_pattern, main_sql, re.IGNORECASE) %} |
| 10 | + {% set testview %} |
| 11 | + [{{ target.schema }}.testview_{{ range(1300, 19000) | random }}] |
| 12 | + {% endset %} |
13 | 13 |
|
14 | | - {% if is_match %} |
15 | | - {% set testview %} |
16 | | - [{{ target.schema }}.testview_{{ range(1300, 19000) | random }}] |
17 | | - {% endset %} |
| 14 | + {% set sql = main_sql.replace("'", "''")%} |
| 15 | + EXEC('create view {{testview}} as {{ sql }};') |
| 16 | + select |
| 17 | + {{ "top (" ~ limit ~ ')' if limit != none }} |
| 18 | + {{ fail_calc }} as failures, |
| 19 | + case when {{ fail_calc }} {{ warn_if }} |
| 20 | + then 'true' else 'false' end as should_warn, |
| 21 | + case when {{ fail_calc }} {{ error_if }} |
| 22 | + then 'true' else 'false' end as should_error |
| 23 | + from ( |
| 24 | + select * from {{testview}} |
| 25 | + ) dbt_internal_test; |
18 | 26 |
|
19 | | - {% set sql = main_sql.replace("'", "''")%} |
20 | | - EXEC('create view {{testview}} as {{ sql }};') |
21 | | - select |
22 | | - {{ "top (" ~ limit ~ ')' if limit != none }} |
23 | | - {{ fail_calc }} as failures, |
24 | | - case when {{ fail_calc }} {{ warn_if }} |
25 | | - then 'true' else 'false' end as should_warn, |
26 | | - case when {{ fail_calc }} {{ error_if }} |
27 | | - then 'true' else 'false' end as should_error |
28 | | - from ( |
29 | | - select * from {{testview}} |
30 | | - ) dbt_internal_test; |
| 27 | + EXEC('drop view {{testview}};') |
31 | 28 |
|
32 | | - EXEC('drop view {{testview}};') |
33 | | - |
34 | | - {% else -%} |
35 | | - select |
36 | | - {{ "top (" ~ limit ~ ')' if limit != none }} |
37 | | - {{ fail_calc }} as failures, |
38 | | - case when {{ fail_calc }} {{ warn_if }} |
39 | | - then 'true' else 'false' end as should_warn, |
40 | | - case when {{ fail_calc }} {{ error_if }} |
41 | | - then 'true' else 'false' end as should_error |
42 | | - from ( |
43 | | - {{ main_sql }} |
44 | | - ) dbt_internal_test |
45 | | - {%- endif -%} |
46 | 29 | {%- endmacro %} |
0 commit comments