Skip to content

Commit

Permalink
Update create
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Hume authored and morsapaes committed Nov 15, 2023
1 parent bf4995e commit 7ae1847
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
23 changes: 23 additions & 0 deletions misc/dbt-materialize/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@
checks, but the value of this feature in a real-time data warehouse is
limited.

* Support for `store_failures_as` which can be `table`, `view`,`ephemeral` or `materialized_view` (like models, a `table` will be a `materialized_view`).

* Project level
```yaml
tests:
my_project:
+store_failures_as: table
```
* Model level
```yaml
models:
- name: my_model
columns:
- name: id
tests:
- not_null:
config:
store_failures_as: view
- unique:
config:
store_failures_as: materialized_view
```
## 1.6.1 - 2023-11-03
* Support the [`ASSERT NOT NULL` option](https://materialize.com/docs/sql/create-materialized-view/#non-null-assertions)
Expand Down
4 changes: 2 additions & 2 deletions misc/dbt-materialize/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ as well as [`--persist-docs`](https://docs.getdbt.com/reference/resource-configs

[`dbt test`](https://docs.getdbt.com/reference/commands/test) is supported.

If you set the optional `--store-failures` flag or [`store-failures` config](https://docs.getdbt.com/reference/resource-configs/store_failures),
dbt will save the results of a test query to a `materialized_view`. These will
If you set the optional flags `--store-failures` or `--store-failures-as` (or config [`store_failures` config](https://docs.getdbt.com/reference/resource-configs/store_failures) or [`store_failures_as` config](https://docs.getdbt.com/reference/resource-configs/store_failures_as)),
By default dbt will save the results of a test query to a `materialized_view`. These will
be created in a schema suffixed or named `dbt_test__audit` by default. Change
this value by setting a `schema` config.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{% if store_failures_as not in ['table', 'view', 'materialized_view'] %}
{{ exceptions.raise_compiler_error(
"'" ~ store_failures_as ~ "' is not a valid value for `store_failures_as`. "
"Accepted values are: ['ephemeral', 'table', 'view', 'materialized_view']"
"Accepted values are: ['table', 'view', 'materialized_view']"
) }}
{% endif %}

Expand All @@ -39,12 +39,18 @@
{% do adapter.drop_relation(old_relation) %}
{% endif %}

{% call statement(auto_begin=True) %}
{{ materialize__create_materialized_view_as(target_relation, sql) }}
{% endcall %}

{% do relations.append(target_relation) %}

{% if store_failures_as == 'view' %}
{% call statement(auto_begin=True) %}
{{ materialize__create_view_as(target_relation, sql) }}
{% endcall %}
{% else %}
{% call statement(auto_begin=True) %}
{{ materialize__create_materialized_view_as(target_relation, sql) }}
{% endcall %}
{% endif %}

{% set main_sql %}
select *
from {{ target_relation }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_tests_run_unsuccessfully_and_raise_appropriate_exception(self, project)
assert "Compilation Error" in result.message
assert "'error' is not a valid value" in result.message
assert (
"Accepted values are: ['ephemeral', 'table', 'view', 'materialized_view']"
"Accepted values are: ['table', 'view', 'materialized_view']"
in result.message
)

Expand Down

0 comments on commit 7ae1847

Please sign in to comment.