-
Notifications
You must be signed in to change notification settings - Fork 47
/
gen_primary_metric_aggregate.sql
79 lines (57 loc) · 2.44 KB
/
gen_primary_metric_aggregate.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
{%- macro gen_primary_metric_aggregate(aggregate, expression) -%}
{{ return(adapter.dispatch('gen_primary_metric_aggregate', 'metrics')(aggregate, expression)) }}
{%- endmacro -%}
{%- macro default__gen_primary_metric_aggregate(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)) }}
{%- elif aggregate == 'median' -%}
{{ return(adapter.dispatch('metric_median', 'metrics')(expression)) }}
{%- elif aggregate == 'derived' -%}
{{ return(adapter.dispatch('metric_derived', '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 -%}
{% macro default__metric_median(expression) %}
median({{ expression }})
{%- endmacro -%}
{% macro bigquery__metric_median(expression) %}
any_value({{ expression }})
{%- endmacro -%}
{% macro postgres__metric_median(expression) %}
percentile_cont(0.5) within group (order by {{ expression }})
{%- endmacro -%}
{% macro default__metric_derived(expression) %}
{{ expression }}
{%- endmacro -%}