update assert_dimension_completeness test
This commit is contained in:
parent
f5311fa954
commit
ca510f91a7
2 changed files with 84 additions and 68 deletions
|
|
@ -1,21 +1,35 @@
|
|||
{% test assert_dimension_completeness(
|
||||
model, column_name, metric_column_name, global_dimension_name="global"
|
||||
model, column_name, metric_column_names, global_dimension_name="global"
|
||||
) %}
|
||||
|
||||
with
|
||||
sum_by_dimension as (
|
||||
|
||||
{% for metric_column_name in metric_column_names %}
|
||||
sum_by_dimension_{{ metric_column_name }} as (
|
||||
select {{ column_name }}, sum({{ metric_column_name }}) as sum_metric
|
||||
from {{ model }}
|
||||
group by {{ column_name }}
|
||||
),
|
||||
global_sum as (
|
||||
global_sum_{{ metric_column_name }} as (
|
||||
select sum({{ metric_column_name }}) as total_metric
|
||||
from {{ model }}
|
||||
where {{ column_name }} = '{{ global_dimension_name }}'
|
||||
),
|
||||
discrepancy_{{ metric_column_name }} as (
|
||||
select *
|
||||
from sum_by_dimension_{{ metric_column_name }}, global_sum_{{ metric_column_name }}
|
||||
where sum_by_dimension_{{ metric_column_name }}.sum_metric != global_sum_{{ metric_column_name }}.total_metric
|
||||
)
|
||||
{% if not loop.last %}, {% endif %}
|
||||
{% endfor %}
|
||||
|
||||
select *
|
||||
from sum_by_dimension, global_sum
|
||||
where sum_by_dimension.sum_metric != global_sum.total_metric
|
||||
{% for metric_column_name in metric_column_names %}
|
||||
{% if loop.first %}
|
||||
select * from discrepancy_{{ metric_column_name }}
|
||||
{% else %}
|
||||
union all
|
||||
select * from discrepancy_{{ metric_column_name }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% endtest %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue