-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added macro __get_test_description and test_description to dq_log * Remove redundant macro * Added macro __get_test_description and test_description to dq_log * Added integration tests for __get_test_description * Added missing underscore * feat: adj auto_generate_test_description * fix: dq_tools__auto_generate_test_description: "1" --------- Co-authored-by: Dat <dat@infinitelambda.com>
- Loading branch information
1 parent
c52acee
commit 0369824
Showing
11 changed files
with
160 additions
and
2 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
81 changes: 81 additions & 0 deletions
81
integration_tests/models/artifacts/test/utilities/_general/test__get_test_description.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,81 @@ | ||
-- test not_null | ||
{% set result_node = { | ||
"test_metadata": { | ||
"name": "not_null", | ||
"kwargs": { | ||
"column_name": "indicator_category", | ||
"model": "{{ get_where_subquery(ref('bi_column_analysis')) }}" | ||
}, | ||
} | ||
} %} | ||
|
||
select '{{ dq_tools.__get_test_description(result_node) }}' as actual, | ||
'The indicator_category column in the bi_column_analysis model should not contain null values.' as expected | ||
|
||
-- test unique | ||
{% set result_node = { | ||
"test_metadata": { | ||
"name": "unique", | ||
"kwargs": { | ||
"column_name": "invocation_id", | ||
"model": "{{ get_where_subquery(ref('test_coverage')) }}" | ||
} | ||
} | ||
} %} | ||
|
||
union all | ||
select '{{ dq_tools.__get_test_description(result_node) }}' as actual, | ||
'The invocation_id column in the test_coverage model should be unique.' as expected | ||
|
||
-- test relationships | ||
{% set result_node = { | ||
|
||
"test_metadata": { | ||
"name": "relationships", | ||
"kwargs": { | ||
"to": "ref('data_test_relationships_a')", | ||
"field": "a_id", | ||
"column_name": "b_id", | ||
"model": "{{ get_where_subquery(ref('data_test_relationships_b')) }}" | ||
} | ||
} | ||
} %} | ||
|
||
union all | ||
select '{{ dq_tools.__get_test_description((result_node)) }}' as actual, | ||
'Each b_id in the data_test_relationships_b model exists as an id in the data_test_relationships_a table.' as expected | ||
|
||
-- test no test description | ||
{% set result_node = { | ||
"test_metadata": { | ||
"name": "not_null_where_db", | ||
"kwargs": { | ||
"column_name": "check_timestamp", | ||
"model": "{{ get_where_subquery(ref('dq_tools_test')) }}" | ||
} | ||
} | ||
} %} | ||
|
||
union all | ||
select '{{ dq_tools.__get_test_description(result_node) }}' as actual, | ||
'' as expected | ||
|
||
{% set result_node = { | ||
"test_metadata": { | ||
"name": "accepted_values", | ||
"kwargs": { | ||
"values": [ | ||
"Simple Statistics" | ||
], | ||
"column_name": "indicator_category", | ||
"model": "{{ get_where_subquery(ref('bi_dq_metrics')) }}" | ||
}, | ||
"namespace": null | ||
}, | ||
"description": "The indicator_category column should only contain simple statistics value" | ||
} %} | ||
|
||
union all | ||
select | ||
'{{ dq_tools.__get_test_description(result_node) }}' as actual, | ||
'The indicator_category column should only contain simple statistics value' as expected |
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,7 @@ | ||
models: | ||
- name: metricflow_time_spine | ||
time_spine: | ||
standard_granularity_column: date_day | ||
columns: | ||
- name: date_day | ||
granularity: day |
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
39 changes: 39 additions & 0 deletions
39
macros/artifacts/test/utilities/general/__get_test_description.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,39 @@ | ||
{% macro __get_test_description(test_node) %} | ||
|
||
{{ return(adapter.dispatch('__get_test_description', 'dq_tools')(test_node)) }} | ||
|
||
{% endmacro %} | ||
|
||
{% macro default____get_test_description(test_node) %} | ||
|
||
{% if test_node.description is defined and test_node.description %} | ||
|
||
{{ return(test_node.description) }} | ||
|
||
{% elif dq_tools.__get_test_type(test_node) != 'singular' and var("dq_tools__auto_generate_test_description", "0") == "1" %} | ||
|
||
{%- set test_name = dq_tools.__get_test_name(test_node) -%} | ||
{%- set column_name = dq_tools.__get_column_name(test_node) -%} | ||
{%- set testing_model = dq_tools.__get_test_model(test_node) -%} | ||
{%- set model_name = dq_tools.__get_relation(testing_model).name | lower -%} | ||
|
||
{%- set generated_description = '' -%} | ||
|
||
{%- if test_name == 'unique' -%} | ||
{%- set generated_description = 'The ' ~ column_name ~ ' column in the ' ~ model_name ~ ' model should be unique.' -%} | ||
{%- elif test_name == 'not_null' -%} | ||
{%- set generated_description = 'The ' ~ column_name ~ ' column in the ' ~ model_name ~ ' model should not contain null values.' -%} | ||
{%- elif test_name == 'accepted_values' -%} | ||
{%- set accepted_values = test_node.test_metadata.kwargs['values'] | join(', ') -%} | ||
{%- set generated_description = 'The ' ~ column_name ~ ' column in the ' ~ model_name ~ ' should be one of ' ~ accepted_values ~ ' values.' -%} | ||
{%- elif test_name == 'relationships' -%} | ||
{%- set to_model = test_node.test_metadata.kwargs.to -%} | ||
{%- set related_model = to_model.split('\'')[1].strip() -%} | ||
{%- set generated_description = 'Each ' ~ column_name ~ ' in the ' ~ model_name ~ ' model exists as an id in the ' ~ related_model ~ ' table.' -%} | ||
{%- endif -%} | ||
|
||
{{ return(generated_description) }} | ||
|
||
{% endif %} | ||
|
||
{% endmacro %} |
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