forked from dbt-labs/dbt-project-evaluator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfct_test_coverage.sql
36 lines (30 loc) · 1.29 KB
/
fct_test_coverage.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
with
test_counts as (
select * from {{ ref('int_model_test_summary') }}
),
conversion as (
select
resource_name,
case when number_of_tests_on_model > 0 then 1 else 0 end as is_tested_model,
{% for model_type in var('model_types') %}
case when model_type = '{{ model_type }}' then 1.0 else NULL end as is_{{ model_type }}_model,
case when number_of_tests_on_model > 0 and model_type = '{{ model_type }}' then 1.0 else 0 end as is_tested_{{ model_type }}_model{% if not loop.last %},{% endif %}
{% endfor %}
from test_counts
),
final as (
select
current_timestamp as measured_at,
count(*) as total_models,
sum(number_of_tests_on_model) as total_tests,
sum(is_tested_model) as tested_models,
round(sum(is_tested_model) * 100.0 / count(*), 2) as test_coverage_pct,
{% for model_type in var('model_types') %}
round(sum(is_tested_{{ model_type }}_model) * 100.0 / nullif(count(is_{{ model_type }}_model), 0), 2) as {{ model_type }}_test_coverage_pct,
{% endfor %}
round(sum(number_of_tests_on_model) * 1.0 / count(*), 4) as test_to_model_ratio
from test_counts
left join conversion
on test_counts.resource_name = conversion.resource_name
)
select * from final