From e525970514d9300efc8cfa3fadf89ab4dd78481d Mon Sep 17 00:00:00 2001 From: p-piwowar Date: Thu, 15 Feb 2024 20:45:11 +0100 Subject: [PATCH] restore creating view during run tests --- .../macros/materializations/tests/helper.sql | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 dbt/include/sqlserver/macros/materializations/tests/helper.sql diff --git a/dbt/include/sqlserver/macros/materializations/tests/helper.sql b/dbt/include/sqlserver/macros/materializations/tests/helper.sql new file mode 100644 index 00000000..fe285cdb --- /dev/null +++ b/dbt/include/sqlserver/macros/materializations/tests/helper.sql @@ -0,0 +1,23 @@ +{% macro sqlserver__get_test_sql(main_sql, fail_calc, warn_if, error_if, limit) -%} + + {% set testview %} + dbo.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 %}