diff --git a/dbt/include/global_project/macros/materializations/tests/helpers.sql b/dbt/include/global_project/macros/materializations/tests/helpers.sql index a385d1ea..ad0b543c 100644 --- a/dbt/include/global_project/macros/materializations/tests/helpers.sql +++ b/dbt/include/global_project/macros/materializations/tests/helpers.sql @@ -16,6 +16,45 @@ +{% macro store_failures(main_sql) -%} + {{ adapter.dispatch('store_failures', 'dbt')(main_sql) }} +{%- endmacro %} + +{% macro default__store_failures(main_sql) -%} + + {% set identifier = model['alias'] %} + {% set old_relation = adapter.get_relation(database=database, schema=schema, identifier=identifier) %} + + -- if `--store-failures` is invoked via command line and `store_failures_as` is not set, + -- config.get('store_failures_as', 'table') returns None, not 'table' + {% set store_failures_as = config.get('store_failures_as') or 'table' %} + {% if store_failures_as not in ['table', 'view'] %} + {{ exceptions.raise_compiler_error( + "'" ~ store_failures_as ~ "' is not a valid value for `store_failures_as`. " + "Accepted values are: ['ephemeral', 'table', 'view']" + ) }} + {% endif %} + + {% set target_relation = api.Relation.create( + identifier=identifier, schema=schema, database=database, type=store_failures_as) -%} %} + + {% if old_relation %} + {% do adapter.drop_relation(old_relation) %} + {% endif %} + + {% call statement(auto_begin=True) %} + {{ get_create_sql(target_relation, main_sql) }} + {% endcall %} + + {{ adapter.commit() }} + + {{ return(target_relation) }} + +{%- endmacro %} + + + + {% macro get_unit_test_sql(main_sql, expected_fixture_sql, expected_column_names) -%} {{ adapter.dispatch('get_unit_test_sql', 'dbt')(main_sql, expected_fixture_sql, expected_column_names) }} {%- endmacro %} diff --git a/dbt/include/global_project/macros/materializations/tests/test.sql b/dbt/include/global_project/macros/materializations/tests/test.sql index a7e5e56a..cac781e5 100644 --- a/dbt/include/global_project/macros/materializations/tests/test.sql +++ b/dbt/include/global_project/macros/materializations/tests/test.sql @@ -34,42 +34,3 @@ {{ return({'relations': relations}) }} {%- endmaterialization -%} - - -{# TODO: move this to helpers.sql #} - -{% macro store_failures(main_sql) -%} - {{ adapter.dispatch('store_failures', 'dbt')(main_sql) }} -{%- endmacro %} - -{% macro default__store_failures(main_sql) -%} - - {% set identifier = model['alias'] %} - {% set old_relation = adapter.get_relation(database=database, schema=schema, identifier=identifier) %} - - -- if `--store-failures` is invoked via command line and `store_failures_as` is not set, - -- config.get('store_failures_as', 'table') returns None, not 'table' - {% set store_failures_as = config.get('store_failures_as') or 'table' %} - {% if store_failures_as not in ['table', 'view'] %} - {{ exceptions.raise_compiler_error( - "'" ~ store_failures_as ~ "' is not a valid value for `store_failures_as`. " - "Accepted values are: ['ephemeral', 'table', 'view']" - ) }} - {% endif %} - - {% set target_relation = api.Relation.create( - identifier=identifier, schema=schema, database=database, type=store_failures_as) -%} %} - - {% if old_relation %} - {% do adapter.drop_relation(old_relation) %} - {% endif %} - - {% call statement(auto_begin=True) %} - {{ get_create_sql(target_relation, main_sql) }} - {% endcall %} - - {{ adapter.commit() }} - - {{ return(target_relation) }} - -{%- endmacro %}