-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tests): make
re_assert
available (#2)
**Features** / **Fixes** - fix `re_assert` argument in `generic_assertions()` test. `assertions()` macros supports private `_node` argument for non-default model parsing. - add a basic test example. - models are not enabled by default. - doc: finalize first `README.md` version. **Breaking Changes** / Issue #2
- Loading branch information
1 parent
ec144f5
commit 34d92d6
Showing
10 changed files
with
199 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
models/examples/basic_example/basic_example_dowstream_model.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
### Combine assertions & generic tests | ||
|
||
#### Example usage | ||
|
||
Suppose we are working with the `d_site` table - you want to use generic tests. | ||
|
||
For instance, the blacklist argument will filter all rows containing at least a "key_1_not_null" error: | ||
|
||
```yml | ||
version: 2 | ||
|
||
models: | ||
- name: basic_test_example_d_site | ||
tests: | ||
- dbt_assertions.generic_assertions: | ||
from_column: errors | ||
blacklist: | ||
- site_id_is_not_null | ||
# `re_assert: true` to use only if your assertion's column | ||
# is not computed and saved in your table. | ||
re_assert: true | ||
|
||
columns: | ||
- name: site_id | ||
- name: country_trigram | ||
- name: open_date | ||
- name: errors | ||
assertions: | ||
site_id_is_not_null: | ||
description: 'Site ID is not null.' | ||
expression: site_id IS NOT NULL | ||
|
||
site_trigram_format: | ||
description: 'Site trigram must contain 3 upper digits' | ||
expression: | | ||
LENGTH(site_trigram) = 3 | ||
AND site_trigram = UPPER(site_trigram) | ||
``` | ||
You can also use the `whitelist` and `from_columns`` arguments, or use the function without arguments (and thus filtering each row based on every assertion). |
15 changes: 15 additions & 0 deletions
15
models/examples/basic_test_example/basic_test_example_d_site.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{{ | ||
config(alias='d_site_test', materialized='table', enabled=false) | ||
}} | ||
|
||
WITH | ||
final AS ( | ||
SELECT 1 AS site_id, 'FRA' AS site_trigram, DATE('2023-01-01') AS open_date | ||
UNION ALL | ||
SELECT 2 AS site_id, 'France' AS site_trigram, DATE('2023-01-01') AS open_date | ||
UNION ALL | ||
SELECT NULL AS site_id, 'Belgium' AS site_trigram, DATE('2023-01-01') AS open_date | ||
) | ||
SELECT | ||
*, | ||
FROM `final` |
28 changes: 28 additions & 0 deletions
28
models/examples/basic_test_example/basic_test_example_d_site.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: basic_test_example_d_site | ||
tests: | ||
- dbt_assertions.generic_assertions: | ||
from_column: errors | ||
blacklist: | ||
- site_id_is_not_null | ||
# `re_assert: true` to use only if your assertion's column | ||
# is not computed and saved in your table. | ||
re_assert: true | ||
|
||
columns: | ||
- name: site_id | ||
- name: country_trigram | ||
- name: open_date | ||
- name: errors | ||
assertions: | ||
site_id_is_not_null: | ||
description: 'Site ID is not null.' | ||
expression: site_id IS NOT NULL | ||
|
||
site_trigram_format: | ||
description: 'Site trigram must contain 3 upper digits' | ||
expression: | | ||
LENGTH(site_trigram) = 3 | ||
AND site_trigram = UPPER(site_trigram) |
Oops, something went wrong.