18
18
{% if lib .time_series is not none -%}
19
19
top_col_values.time_period as time_period,
20
20
top_col_values.time_period_utc as time_period_utc,
21
- {% - endif -%}
21
+ {% endif -%}
22
22
RANK() OVER({{- render_data_grouping('top_col_values', indentation = ' ', partition_by_enabled=true) }}
23
- ORDER BY top_col_values.total_values DESC) as top_values_rank {{- render_data_grouping('top_col_values', indentation = ' ') }}
23
+ ORDER BY top_col_values.total_values DESC) as top_values_rank {{- render_data_grouping('top_col_values', indentation = ' ') }}
24
24
FROM
25
25
(
26
26
SELECT
31
31
FROM
32
32
{{ lib.render_target_table() }} AS analyzed_table
33
33
{{- lib.render_where_clause(extra_filter = lib.render_target_column('analyzed_table') ~ ' IS NOT NULL', indentation = ' ') }}
34
- GROUP BY {{ render_grouping_columns() }} top_value
35
- ORDER BY {{ render_grouping_columns() }} total_values DESC
34
+ GROUP BY {{ render_grouping_columns() - }} top_value
35
+ ORDER BY {{ render_grouping_columns() - }} total_values DESC
36
36
) AS top_col_values
37
37
) AS top_values
38
38
WHERE top_values_rank <= {{ parameters.top }}
39
39
{% - endmacro -%}
40
40
41
41
{% macro render_grouping_columns () %}
42
- {% - if (lib .data_groupings is not none and (lib .data_groupings | length ()) > 0) or lib .time_series is not none %}
43
- {{ lib.render_grouping_column_names() }} {{ ',' }}
42
+ {% - if (lib .data_groupings is not none and (lib .data_groupings | length ()) > 0) or lib .time_series is not none - %}
43
+ {{ lib.render_grouping_column_names() }} {{- ', ' - }}
44
44
{% - endif -%}
45
45
{% endmacro %}
46
46
47
47
{% - macro render_data_grouping (table_alias_prefix = '' , indentation = '' , partition_by_enabled = false ) -%}
48
48
49
- {% - if lib .time_series is not none and partition_by_enabled == true -%} PARTITION BY top_col_values.time_period{% - endif -%}
49
+ {% - if partition_by_enabled == true -%} PARTITION BY
50
+ {% - if lib .time_series is not none -%}
51
+ {{" "}}top_col_values.time_period
52
+ {% - elif lib .data_groupings is none -%}
53
+ {{" "}}NULL
54
+ {% - endif -%}
55
+ {% - endif -%}
50
56
51
57
{% - if lib .data_groupings is not none and (lib .data_groupings | length ()) > 0 -%}
52
58
{% - for attribute in lib .data_groupings -%}
53
- {% if lib .time_series is none and loop .index == 1 and partition_by_enabled == true -%}
54
- PARTITION BY
55
- {% - else -%}
56
- {{ ',' }}
57
- {% - endif -%}
59
+ {{- "" if loop.first and lib.time_series is none and partition_by_enabled else "," -}}
58
60
{% - with data_grouping_level = lib .data_groupings [attribute ] -%}
59
61
{% - if data_grouping_level .source == 'tag' -%}
60
62
{{ indentation }}{{ lib.make_text_constant(data_grouping_level.tag) }}
@@ -73,17 +75,17 @@ SELECT
73
75
{{- lib.render_data_grouping_projections('analyzed_table') }}
74
76
{{- lib.render_time_dimension_projection('analyzed_table') }}
75
77
FROM {{ lib.render_target_table() }} AS analyzed_table
76
- {% - else %}
78
+ {% - else %}
77
79
COUNT(DISTINCT
78
80
CASE
79
81
WHEN top_values.top_value IN ({{ extract_in_list(parameters.expected_values) }}) THEN top_values.top_value
80
82
ELSE NULL
81
83
END
82
84
) AS actual_value,
83
85
MAX({{ parameters.expected_values | length }}) AS expected_value
84
- {% if lib .time_series is not none -%}
85
- , top_values.time_period
86
- , top_values.time_period_utc
86
+ {% - if lib .time_series is not none -%} {{- "," } }
87
+ top_values.time_period,
88
+ top_values.time_period_utc
87
89
{% - endif -%}
88
90
{{- render_data_grouping('top_values', indentation = lib.eol() ~ ' ') }}
89
91
{{ render_from_subquery() }}
0 commit comments