Skip to content

Commit

Permalink
Move to helpers.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
dbeatty10 committed Dec 6, 2024
1 parent 5e9318d commit aa6c793
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
39 changes: 0 additions & 39 deletions dbt/include/global_project/macros/materializations/tests/test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

0 comments on commit aa6c793

Please sign in to comment.