Skip to content

Commit

Permalink
Fix broken categorization in transform_dbt_test_results.py and remo…
Browse files Browse the repository at this point in the history
…ve `dbt_utils` dependency (#474)

* Fix test categorization in transform_dbt_test_results.py by removing refs to dbt project name

* Remove unnecessary dependency on dbt_utils
  • Loading branch information
jeancochrane authored May 24, 2024
1 parent a0001a4 commit 4a982dc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
34 changes: 15 additions & 19 deletions .github/scripts/transform_dbt_test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,13 @@
# Mapping that defines category names that should be reported for tests
# based on their generics
TEST_CATEGORIES = {
"macro.athena.test_accepted_range": "incorrect_values",
"macro.dbt_utils.test_accepted_range": "incorrect_values",
"macro.athena.test_accepted_values": "incorrect_values",
"macro.athena.test_not_accepted_values": "incorrect_values",
"macro.dbt_utils.test_not_accepted_values": "incorrect_values",
"macro.athena.test_unique_combination_of_columns": "duplicate_records",
"macro.dbt_utils.test_unique_combination_of_columns": "duplicate_records",
"macro.athena.test_not_null": "missing_values",
"macro.athena.test_is_null": "missing_values",
"macro.athena.test_res_class_matches_pardat": "class_mismatch_or_issue",
"test_accepted_range": "incorrect_values",
"test_accepted_values": "incorrect_values",
"test_not_accepted_values": "incorrect_values",
"test_unique_combination_of_columns": "duplicate_records",
"test_not_null": "missing_values",
"test_is_null": "missing_values",
"test_res_class_matches_pardat": "class_mismatch_or_issue",
}
# Fallback for tests whose category we can't determine from either the
# test name, the `meta.category` attribute, or the TEST_CATEGORIES mapping
Expand Down Expand Up @@ -1184,16 +1181,15 @@ def get_category_from_node(node: typing.Dict) -> str:
return meta_category

for dependency_macro in node["depends_on"]["macros"]:
if custom_test_name := TEST_CATEGORIES.get(dependency_macro):
# Macro names in the DAG are fully qualified following the pattern
# `macro.<project_name>.<macro_name>`, so remove the prefix to extract
# just the name of the macro
cleaned_macro_name = dependency_macro.split(".")[-1]
if custom_test_name := TEST_CATEGORIES.get(cleaned_macro_name):
return custom_test_name
# Custom generic tests are always formatted like
# macro.dbt.test_<generic_name>
if dependency_macro.startswith("macro.athena.test_"):
return dependency_macro.split("macro.athena.test_")[-1]
# dbt_utils generic tests are always formatted like
# macro.dbt_utils.test_<generic_name>
if dependency_macro.startswith("macro.dbt_utils.test_"):
return dependency_macro.split("macro.dbt_utils.test_")[-1]
# Custom generic tests are always formatted like test_<generic_name>
if cleaned_macro_name.startswith("test_"):
return cleaned_macro_name.split("test_")[-1]

return DEFAULT_TEST_CATEGORY

Expand Down
4 changes: 0 additions & 4 deletions dbt/package-lock.yml

This file was deleted.

3 changes: 0 additions & 3 deletions dbt/packages.yml

This file was deleted.

2 changes: 1 addition & 1 deletion dbt/tests/generic/test_sequential_values.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
additional_select_columns=[]
) %}

{%- set previous_column_name = "previous_" ~ dbt_utils.slugify(column_name) -%}
{%- set previous_column_name = "previous_" ~ slugify(column_name) -%}

{%- if group_by_columns | length() > 0 -%}
{%- set select_gb_cols = group_by_columns | join(",") -%}
Expand Down

0 comments on commit 4a982dc

Please sign in to comment.