Skip to content

Commit

Permalink
Merge pull request #408 from sadahry/log-own-custom-rules
Browse files Browse the repository at this point in the history
feat: Log own custom rules
  • Loading branch information
graciegoheen authored Feb 1, 2024
2 parents 7987ee8 + 11f8fda commit eb32a30
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
13 changes: 13 additions & 0 deletions docs/customization/issues-in-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,16 @@ The macro accepts two parameters:
- to pick between 2 types of formatting, set `format='table'` (default) or `format='csv'`
- to add quotes to the database and schema (default = no quote), set ``quote='`'`` or `quote='"'`

## Logging your custom rules

You can also log the results of your custom rules by applying `dbt_project_evaluator.is_empty` to
the custom models.

```yaml
models:
- name: my_custom_rule_model
description: This is my custom project evaluator check
tests:
- dbt_project_evaluator.is_empty
```
19 changes: 17 additions & 2 deletions macros/on-run-end/print_dbt_project_evaluator_issues.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@
{%- if flags.WHICH in ["build","test"] -%}
{{ print("\n### List of issues raised by dbt_project_evaluator ###") }}

{#-
if you create custom dbt_project_evaluator rules on your package using the test `dbt_project_evaluator.is_empty`,
the test name should start with the same name as the default.
-#}
{% set test_name_prefix_of_custom_rules = var(
"test_name_prefix_of_custom_rules",
default="dbt_project_evaluator_is_empty_",
) %}

{% for result in results | selectattr('failures') | selectattr('failures', '>', 0) %}

{% if result.node.fqn[0] == "dbt_project_evaluator" %}
{% set is_test = result.node.config.materialized == "test" %}
{% set package_name = result.node.package_name %}
{% set resource_name = result.node.name %}
{% if is_test and (
package_name == "dbt_project_evaluator"
or resource_name.startswith(test_name_prefix_of_custom_rules)
) %}

{{ print("\n-- " ~ result.node.alias ~ " --") }}
{{ print("\n-- " ~ result.node.fqn | join(".") ~ " --") }}

{% set unique_id_model_checked = result.node.depends_on.nodes[0] %}

Expand Down

0 comments on commit eb32a30

Please sign in to comment.