-
Notifications
You must be signed in to change notification settings - Fork 3
/
get_test_suggestions.sql
99 lines (93 loc) · 3.44 KB
/
get_test_suggestions.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
{% macro get_test_suggestions(
table_relation,
sample = false,
limit = 10000,
resource_type = "models",
column_config = {},
exclude_types = [],
exclude_cols = [],
tests = ["uniqueness", "accepted_values", "range", "string_length", "recency"],
uniqueness_composite_key_length = 1,
accepted_values_max_cardinality = 5,
range_stddevs = 0,
string_length_stddevs = 0,
recency_stddevs = 1,
dbt_config = None,
return_object = false
) %}
{# Run macro for the specific target DB #}
{% if execute %}
{% if "uniqueness" in tests %}
{% set dbt_config = testgen.get_uniqueness_test_suggestions(
table_relation=table_relation,
sample=sample,
limit=limit,
resource_type=resource_type,
column_config=column_config,
exclude_types=exclude_types,
exclude_cols=exclude_cols,
composite_key_length=uniqueness_composite_key_length,
dbt_config=dbt_config
) %}
{% endif %}
{% if "accepted_values" in tests %}
{% set dbt_config = testgen.get_accepted_values_test_suggestions(
table_relation=table_relation,
sample=sample,
limit=limit,
resource_type=resource_type,
column_config=column_config,
exclude_types=exclude_types,
exclude_cols=exclude_cols,
max_cardinality=accepted_values_max_cardinality,
dbt_config=dbt_config
) %}
{% endif %}
{% if "range" in tests %}
{% set dbt_config = testgen.get_range_test_suggestions(
table_relation=table_relation,
sample=sample,
limit=limit,
resource_type=resource_type,
column_config=column_config,
exclude_types=exclude_types,
exclude_cols=exclude_cols,
stddevs=range_stddevs,
dbt_config=dbt_config
) %}
{% endif %}
{% if "string_length" in tests %}
{% set dbt_config = testgen.get_string_length_test_suggestions(
table_relation=table_relation,
sample=sample,
limit=limit,
resource_type=resource_type,
column_config=column_config,
exclude_types=exclude_types,
exclude_cols=exclude_cols,
stddevs=string_length_stddevs,
dbt_config=dbt_config
) %}
{% endif %}
{% if "recency" in tests %}
{% set dbt_config = testgen.get_recency_test_suggestions(
table_relation=table_relation,
sample=sample,
limit=limit,
resource_type=resource_type,
column_config=column_config,
exclude_types=exclude_types,
exclude_cols=exclude_cols,
stddevs=recency_stddevs,
dbt_config=dbt_config
) %}
{% endif %}
{% if return_object %}
{{ return(dbt_config) }}
{% else %}
{% set the_yaml = testgen.to_yaml(dbt_config) %}
{{ print(the_yaml) }}
{{ return(the_yaml) }}
{% endif %}
{% endif %}
{%- endmacro %}