Skip to content

Commit

Permalink
feat(vars): add default column variable (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
axel_thevenot authored and AxelThevenot committed Feb 27, 2024
1 parent 48a72a1 commit 74ed79a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ This package do not have dependencies.

## Variables

This package do not have variables.
The following variable **can** be defined in your `dbt_project.yml` file to change the default `exceptions` column name used by the package.

```yml
vars:
"dbt_assertions:default_column": "exceptions"
```
## Basic Example
Expand Down
4 changes: 4 additions & 0 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ require-dbt-version: [">=1.7.0", "<2.0.0"]
target-path: "target"
clean-targets: ["target", "dbt_packages"]
macro-paths: ["macros"]


vars:
"dbt_assertions:default_column": "exceptions"
2 changes: 1 addition & 1 deletion macros/assertions.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- macro assertions(column='exceptions', _node=none) %}
{%- macro assertions(column=var('dbt_assertions:default_column', 'exceptions'), _node=none) %}
{#-
Generates row-level assertions based on the schema model YAML.

Expand Down
7 changes: 6 additions & 1 deletion macros/assertions_filter.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{%- macro assertions_filter(column='exceptions', exclude_list=none, include_list=none, reverse=false) -%}
{%- macro assertions_filter(
column=var('dbt_assertions:default_column', 'exceptions'),
exclude_list=none,
include_list=none,
reverse=false
) -%}
{#-
Generates an expression to filter rows based on assertions results.

Expand Down
8 changes: 7 additions & 1 deletion tests/generic/generic_assertions.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{% test generic_assertions(model, column='exceptions', exclude_list=none, include_list=none, re_assert=False) %}
{% test generic_assertions(
model,
column=var('dbt_assertions:default_column', 'exceptions'),
exclude_list=none,
include_list=none,
re_assert=False
) %}
{#-
Generates a test SELECT expression to get rows based on exceptions.

Expand Down

0 comments on commit 74ed79a

Please sign in to comment.