forked from dbt-labs/dbt_metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecondary_calculation_period_to_date.sql
38 lines (33 loc) · 1.17 KB
/
secondary_calculation_period_to_date.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
{% macro default__secondary_calculation_period_to_date(metric_name, dimensions, calc_config) %}
{%- set calc_sql %}
{{- adapter.dispatch('aggregate_primary_metric', 'metrics')(calc_config.aggregate, metric_name) -}}
over (
partition by date_{{ calc_config.period }}
{% if dimensions -%}
, {{ dimensions | join(", ") }}
{%- endif %}
order by period
rows between unbounded preceding and current row
)
{%- endset %}
{%- do return (calc_sql) %}
{% endmacro %}
{% macro period_to_date(aggregate, period, alias) %}
{% set missing_args = [] %}
{% if not aggregate %}
{% set _ = missing_args.append("aggregate") %}
{% endif %}
{% if not period %}
{% set _ = missing_args.append("period") %}
{% endif %}
{% if missing_args | length > 0 %}
{% do exceptions.raise_compiler_error( missing_args | join(", ") ~ ' not provided to period_to_date') %}
{% endif %}
{% do return ({
"calculation": "period_to_date",
"aggregate": aggregate,
"period": period,
"alias": alias
})
%}
{% endmacro %}