|
94 | 94 | ), |
95 | 95 |
|
96 | 96 | column_metrics_unpivot as ( |
97 | | - {{ elementary.get_column_metrics_unpivot_query(column_metrics, column_obj, metric_name_to_type, timestamp_column, dimensions) }} |
| 97 | + {%- if column_metrics %} |
| 98 | + {% for metric_name, metric_type in metric_name_to_type.items() %} |
| 99 | + select |
| 100 | + {{ elementary.const_as_string(column_obj.name) }} as edr_column_name, |
| 101 | + bucket_start, |
| 102 | + bucket_end, |
| 103 | + {% if timestamp_column %} |
| 104 | + {{ elementary.timediff("hour", "bucket_start", "bucket_end") }} as bucket_duration_hours, |
| 105 | + {% else %} |
| 106 | + {{ elementary.null_int() }} as bucket_duration_hours, |
| 107 | + {% endif %} |
| 108 | + {% if dimensions | length > 0 %} |
| 109 | + {{ elementary.const_as_string(elementary.join_list(dimensions, separator='; ')) }} as dimension, |
| 110 | + {{ elementary.list_concat_with_separator(prefixed_dimensions, separator='; ') }} as dimension_value, |
| 111 | + {% else %} |
| 112 | + {{ elementary.null_string() }} as dimension, |
| 113 | + {{ elementary.null_string() }} as dimension_value, |
| 114 | + {% endif %} |
| 115 | + {{ elementary.edr_cast_as_float(metric_type) }} as metric_value, |
| 116 | + {{ elementary.edr_cast_as_string(elementary.edr_quote(metric_name)) }} as metric_name, |
| 117 | + {{ elementary.edr_cast_as_string(elementary.edr_quote(metric_type)) }} as metric_type |
| 118 | + from column_metrics where {{ metric_type }} is not null |
| 119 | + {% if not loop.last %} union all {% endif %} |
| 120 | + {%- endfor %} |
| 121 | + {%- else %} |
| 122 | + {{ elementary.empty_table([('edr_column_name','string'),('bucket_start','timestamp'),('bucket_end','timestamp'),('bucket_duration_hours','int'),('dimension','string'),('dimension_value','string'),('metric_name','string'),('metric_type','string'),('metric_value','float')]) }} |
| 123 | + {%- endif %} |
98 | 124 | ), |
99 | 125 |
|
100 | 126 | metrics_final as ( |
|
142 | 168 |
|
143 | 169 | {% endmacro %} |
144 | 170 |
|
145 | | -{% macro get_column_metrics_unpivot_query(column_metrics, column_obj, metric_name_to_type, timestamp_column, dimensions) %} |
146 | | - {{ return(adapter.dispatch('get_column_metrics_unpivot_query', 'elementary')(column_metrics, column_obj, metric_name_to_type, timestamp_column, dimensions)) }} |
147 | | -{% endmacro %} |
148 | | - |
149 | | -{% macro default__get_column_metrics_unpivot_query(column_metrics, column_obj, metric_name_to_type, timestamp_column, dimensions) %} |
150 | | - {%- if column_metrics %} |
151 | | - {% for metric_name, metric_type in metric_name_to_type.items() %} |
152 | | - select |
153 | | - {{ elementary.const_as_string(column_obj.name) }} as edr_column_name, |
154 | | - bucket_start, |
155 | | - bucket_end, |
156 | | - {% if timestamp_column %} |
157 | | - {{ elementary.timediff("hour", "bucket_start", "bucket_end") }} as bucket_duration_hours, |
158 | | - {% else %} |
159 | | - {{ elementary.null_int() }} as bucket_duration_hours, |
160 | | - {% endif %} |
161 | | - {% if dimensions | length > 0 %} |
162 | | - {{ elementary.const_as_string(elementary.join_list(dimensions, separator='; ')) }} as dimension, |
163 | | - {{ elementary.list_concat_with_separator(prefixed_dimensions, separator='; ') }} as dimension_value, |
164 | | - {% else %} |
165 | | - {{ elementary.null_string() }} as dimension, |
166 | | - {{ elementary.null_string() }} as dimension_value, |
167 | | - {% endif %} |
168 | | - {{ elementary.edr_cast_as_float(metric_type) }} as metric_value, |
169 | | - {{ elementary.edr_cast_as_string(elementary.edr_quote(metric_name)) }} as metric_name, |
170 | | - {{ elementary.edr_cast_as_string(elementary.edr_quote(metric_type)) }} as metric_type |
171 | | - from column_metrics where {{ metric_type }} is not null |
172 | | - {% if not loop.last %} union all {% endif %} |
173 | | - {%- endfor %} |
174 | | - {%- else %} |
175 | | - {{ elementary.empty_table([('edr_column_name','string'),('bucket_start','timestamp'),('bucket_end','timestamp'),('bucket_duration_hours','int'),('dimension','string'),('dimension_value','string'),('metric_name','string'),('metric_type','string'),('metric_value','float')]) }} |
176 | | - {%- endif %} |
177 | | -{% endmacro %} |
178 | | - |
179 | | -{% macro clickhouse__get_column_metrics_unpivot_query(column_metrics, column_obj, metric_name_to_type, timestamp_column, dimensions) %} |
180 | | - {%- if column_metrics %} |
181 | | - {% for metric_name, metric_type in metric_name_to_type.items() %} |
182 | | - select |
183 | | - {{ elementary.const_as_string(column_obj.name) }} as edr_column_name, |
184 | | - bucket_start, |
185 | | - bucket_end, |
186 | | - {% if timestamp_column %} |
187 | | - {{ elementary.timediff("hour", "bucket_start", "bucket_end") }} as bucket_duration_hours, |
188 | | - {% else %} |
189 | | - {{ elementary.null_int() }} as bucket_duration_hours, |
190 | | - {% endif %} |
191 | | - {% if dimensions | length > 0 %} |
192 | | - {{ elementary.const_as_string(elementary.join_list(dimensions, separator='; ')) }} as dimension, |
193 | | - {{ elementary.list_concat_with_separator(prefixed_dimensions, separator='; ') }} as dimension_value, |
194 | | - {% else %} |
195 | | - CAST(NULL AS Nullable(String)) as dimension, |
196 | | - CAST(NULL AS Nullable(String)) as dimension_value, |
197 | | - {% endif %} |
198 | | - {{ elementary.edr_cast_as_float(metric_type) }} as metric_value, |
199 | | - cast({{ elementary.edr_quote(metric_name) }} as Nullable({{ elementary.edr_type_string() }})) as metric_name, |
200 | | - cast({{ elementary.edr_quote(metric_type) }} as Nullable({{ elementary.edr_type_string() }})) as metric_type |
201 | | - from column_metrics where {{ metric_type }} is not null |
202 | | - {% if not loop.last %} union all {% endif %} |
203 | | - {%- endfor %} |
204 | | - {%- else %} |
205 | | - {{ elementary.empty_table([('edr_column_name','string'),('bucket_start','timestamp'),('bucket_end','timestamp'),('bucket_duration_hours','int'),('dimension','string'),('dimension_value','string'),('metric_name','string'),('metric_type','string'),('metric_value','float')]) }} |
206 | | - {%- endif %} |
207 | | -{% endmacro %} |
208 | | - |
209 | 171 | {% macro select_dimensions_columns(dimension_columns, as_prefix="") %} |
210 | 172 | {% set select_statements %} |
211 | 173 | {%- for column in dimension_columns -%} |
|
0 commit comments