forked from dbt-labs/dbt_metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaggregate_primary_metric.sql
57 lines (42 loc) · 1.79 KB
/
aggregate_primary_metric.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
--TODO: Do we have a list of aggregations that we're supporting on day one?
{% macro aggregate_primary_metric(aggregate, expression) %}
{{ return(adapter.dispatch('aggregate_primary_metric', 'metrics')(aggregate, expression)) }}
{% endmacro %}
{% macro default__aggregate_primary_metric(aggregate, expression) %}
{% if aggregate == 'count' %}
{{ return(adapter.dispatch('metric_count', 'metrics')(expression)) }}
{% elif aggregate == 'count_distinct' %}
{{ return(adapter.dispatch('metric_count_distinct', 'metrics')(expression)) }}
{% elif aggregate == 'average' %}
{{ return(adapter.dispatch('metric_average', 'metrics')(expression)) }}
{% elif aggregate == 'max' %}
{{ return(adapter.dispatch('metric_max', 'metrics')(expression)) }}
{% elif aggregate == 'min' %}
{{ return(adapter.dispatch('metric_min', 'metrics')(expression)) }}
{% elif aggregate == 'sum' %}
{{ return(adapter.dispatch('metric_sum', 'metrics')(expression)) }}
{% else %}
{% do exceptions.raise_compiler_error("Unknown aggregation style: " ~ aggregate) %}
{% endif %}
{% endmacro %}
{% macro default__metric_count(expression) %}
count({{ expression }})
{% endmacro %}
{% macro default__metric_count_distinct(expression) %}
count(distinct {{ expression }})
{% endmacro %}
{% macro default__metric_average(expression) %}
avg({{ expression }})
{% endmacro %}
{% macro redshift__metric_average(expression) %}
avg(cast({{ expression }} as float))
{% endmacro %}
{% macro default__metric_max(expression) %}
max({{ expression }})
{% endmacro %}
{% macro default__metric_min(expression) %}
min({{ expression }})
{% endmacro %}
{% macro default__metric_sum(expression) %}
sum({{ expression }})
{% endmacro %}