|
1 | 1 | {% import '/dialects/sqlserver.sql.jinja2' as lib with context -%}
|
2 | 2 |
|
3 |
| -{% macro extract_in_list(values_list, column_prefix = none, column_suffix = none, separate_by_comma = false) %} |
| 3 | +{%- macro extract_in_list(values_list, column_prefix = none, column_suffix = none, separate_by_comma = false) %} |
4 | 4 | {%- set column_names = table.columns if values_list is none or (values_list | length()) == 0 else values_list -%}
|
5 | 5 | {%- for item in column_names -%}
|
6 | 6 | {{ (column_prefix) if column_prefix is not none -}} {{- lib.quote_identifier(item) -}} {{- (column_suffix) if column_suffix is not none -}} {{- ", " if not loop.last }} {{- "', ', " if separate_by_comma and not loop.last }}
|
7 | 7 | {%- endfor -%}
|
| 8 | +{% endmacro -%} |
| 9 | + |
| 10 | +{% macro render_group_by(table_alias_prefix = 'grouping_table', indentation = ' ') %} |
| 11 | + {%- if (lib.data_groupings is not none and (lib.data_groupings | length()) > 0) or lib.time_series is not none -%} |
| 12 | + GROUP BY |
| 13 | + {%- endif -%} |
| 14 | + {%- if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -%} |
| 15 | + {%- for attribute in lib.data_groupings -%} |
| 16 | + {{- ',' if not loop.first -}}{{- lib.eol() }} |
| 17 | + {{ indentation }}{{ table_alias_prefix }}.grouping_{{ attribute -}} |
| 18 | + {%- endfor -%} |
| 19 | + {%- endif -%} |
| 20 | + {%- if lib.time_series is not none -%} |
| 21 | + {{ ',' if lib.data_groupings is not none and (lib.data_groupings | length()) > 0 -}}{{- lib.eol() -}} |
| 22 | + {{ indentation }}time_period,{{ lib.eol() -}} |
| 23 | + {{ indentation }}time_period_utc |
| 24 | + {%- endif -%} |
8 | 25 | {% endmacro %}
|
9 | 26 |
|
10 | 27 | SELECT
|
|
20 | 37 | {{- lib.render_time_dimension_projection('analyzed_table', indentation=' ') }}
|
21 | 38 | FROM {{ lib.render_target_table() }} AS analyzed_table
|
22 | 39 | {{- lib.render_where_clause(indentation=' ', extra_filter = 'COALESCE(' ~ extract_in_list(parameters.columns, column_prefix='CAST(', column_suffix=' AS VARCHAR)') ~ ') IS NOT NULL') }}
|
23 |
| - GROUP BY {{- extract_in_list(parameters.columns) -}} {{- (", " ~ lib.render_grouping_column_names()) if (lib.data_groupings is not none and (lib.data_groupings | length()) > 0) or lib.time_series is not none }} |
| 40 | + GROUP BY {{ extract_in_list(parameters.columns) -}} {{- (", " ~ lib.render_grouping_column_names()) if (lib.data_groupings is not none and (lib.data_groupings | length()) > 0) or lib.time_series is not none }} |
24 | 41 | ) grouping_table
|
25 |
| -{{- lib.render_group_by() -}} |
26 |
| -{{- lib.render_order_by() -}} |
| 42 | +{{ render_group_by('grouping_table') }} |
0 commit comments