forked from dbt-labs/dbt_metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate_aggregate_coherence.sql
23 lines (20 loc) · 1.05 KB
/
validate_aggregate_coherence.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{% macro validate_aggregate_coherence(metric_aggregate, calculation_aggregate) %}
{% set allowlist = metrics.get_metric_allowlist()[metric_aggregate] %}
{% if (calculation_aggregate not in allowlist) %}
{% do exceptions.raise_compiler_error("Can't calculate secondary aggregate " ~ calculation_aggregate ~ " when metric's aggregation is " ~ metric_aggregate ~ ". Allowed options are " ~ allowlist ~ ".") %}
{% endif %}
{% endmacro %}
{% macro get_metric_allowlist() %}
{{ return(adapter.dispatch('get_metric_allowlist', 'metrics')()) }}
{% endmacro %}
{% macro default__get_metric_allowlist() %}
{# Keys are the primary aggregation, values are the permitted aggregations to run in secondary calculations. #}
{% do return ({
"average": ['min', 'max'],
"count": ['min', 'max', 'sum', 'average'],
"count_distinct": ['min', 'max', 'sum', 'average'],
"sum": ['min', 'max', 'sum', 'average'],
"max": ['min', 'max', 'sum', 'average'],
"min": ['min', 'max', 'sum', 'average'],
}) %}
{% endmacro %}