33{% endmacro %}
44
55{% macro default__gen_base_query(metric_dictionary, grain, dimensions, secondary_calculations, start_date, end_date, calendar_tbl, relevant_periods, calendar_dimensions, total_dimension_count) %}
6-
76 {# This is the "base" CTE which selects the fields we need to correctly
8- calculate the metric. # }
7+ calculate the metric. - # }
98 select
10-
11- {% if grain %}
9+ {% if grain - %}
1210 cast(base_model.{{metric_dictionary .timestamp }} as date ) as metric_date_day,
1311 calendar_table .date_ {{ grain }} as date_{{grain}},
1412 calendar_table .date_day as window_filter_date,
1715 calendar_table .date_ {{ period }},
1816 {% endfor - %}
1917 {%- endif - %}
20- {%- endif - %}
21-
22- {% for dim in dimensions %}
18+ {%- endif %}
19+ { # - -#}
20+ {%- for dim in dimensions - %}
2321 base_model.{{ dim }},
24- {% endfor %}
25-
26- {% for calendar_dim in calendar_dimensions %}
22+ {%- endfor - %}
23+ {%- for calendar_dim in calendar_dimensions - %}
2724 calendar_table.{{ calendar_dim }},
28- {% endfor %}
29-
30-
31- {%- if metric_dictionary .expression and metric_dictionary .expression | replace(' *' , ' ' ) | trim != ' ' %}
32-
33- ({{ metric_dictionary .expression }}) as property_to_aggregate
34- {%- elif metric_dictionary .calculation_method == ' count' - %}
35- {# We use 1 as the property to aggregate in count so that it matches count(*) #}
36- 1 as property_to_aggregate
37- {%- else - %}
38- {%- do exceptions .raise_compiler_error (" Expression to aggregate is required for non-count aggregation in metric `" ~ metric_dictionary .name ~ " `" ) - %}
39- {%- endif %}
40-
41-
25+ {%- endfor - %}
26+ {{ metrics .gen_property_to_aggregate (metric_dictionary, grain, dimensions, calendar_dimensions) }}
4227 from {{ metric_dictionary .metric_model }} base_model
43-
44- {% if grain or calendar_dimensions|length > 0 %}
28+ { # -#}
29+ {%- if grain or calendar_dimensions|length > 0 - %}
4530 {{ metrics .gen_calendar_table_join (metric_dictionary, calendar_tbl) }}
46- {% endif %}
47-
31+ {%- endif - %}
32+ { # #}
4833 where 1 = 1
49-
34+ { # - -#}
5035 {{ metrics .gen_filters (metric_dictionary, start_date, end_date) }}
5136
5237{%- endmacro - %}
0 commit comments