You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: macros/edr/data_monitoring/anomaly_detection/get_anomaly_scores_query.sql
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -164,7 +164,7 @@
164
164
bucket_duration_hours,
165
165
updated_at,
166
166
avg(metric_value) over (partition by metric_name, full_table_name, column_name, dimension, dimension_value, bucket_seasonality order by bucket_end asc rows between unbounded preceding and current row) as training_avg,
167
-
stddev(metric_value) over (partition by metric_name, full_table_name, column_name, dimension, dimension_value, bucket_seasonality order by bucket_end asc rows between unbounded preceding and current row) as training_stddev,
167
+
{{ elementary.standard_deviation('metric_value') }} over (partition by metric_name, full_table_name, column_name, dimension, dimension_value, bucket_seasonality order by bucket_end asc rows between unbounded preceding and current row) as training_stddev,
168
168
count(metric_value) over (partition by metric_name, full_table_name, column_name, dimension, dimension_value, bucket_seasonality order by bucket_end asc rows between unbounded preceding and current row) as training_set_size,
169
169
last_value(bucket_end) over (partition by metric_name, full_table_name, column_name, dimension, dimension_value, bucket_seasonality order by bucket_end asc rows between unbounded preceding and current row) training_end,
170
170
first_value(bucket_end) over (partition by metric_name, full_table_name, column_name, dimension, dimension_value, bucket_seasonality order by bucket_end asc rows between unbounded preceding and current row) as training_start
Copy file name to clipboardExpand all lines: macros/edr/tests/test_utils/get_anomaly_query.sql
+64-25Lines changed: 64 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -60,38 +60,77 @@ case when
60
60
from anomaly_scores
61
61
),
62
62
63
-
final_results as (
64
-
select
65
-
metric_value as value,
66
-
training_avg as average,
67
-
{# when there is an anomaly we would want to use the last value of the metric (lag), otherwise visually the expectations would look out of bounds #}
68
-
case
69
-
when is_anomalous = TRUE and'{{ test_configuration.anomaly_direction }}'='spike' then
70
-
lag(metric_value) over (partition by full_table_name, column_name, metric_name, dimension, dimension_value, bucket_seasonality order by bucket_end)
71
-
when is_anomalous = TRUE and'{{ test_configuration.anomaly_direction }}'!='spike' then
72
-
lag(min_metric_value) over (partition by full_table_name, column_name, metric_name, dimension, dimension_value, bucket_seasonality order by bucket_end)
73
-
when '{{ test_configuration.anomaly_direction }}'='spike' then metric_value
74
-
else min_metric_value end as min_value,
75
-
case
76
-
when is_anomalous = TRUE and'{{ test_configuration.anomaly_direction }}'='drop' then
77
-
lag(metric_value) over (partition by full_table_name, column_name, metric_name, dimension, dimension_value, bucket_seasonality order by bucket_end)
78
-
when is_anomalous = TRUE and'{{ test_configuration.anomaly_direction }}'!='drop' then
79
-
lag(max_metric_value) over (partition by full_table_name, column_name, metric_name, dimension, dimension_value, bucket_seasonality order by bucket_end)
80
-
when '{{ test_configuration.anomaly_direction }}'='drop' then metric_value
{# when there is an anomaly we would want to use the last value of the metric (lag), otherwise visually the expectations would look out of bounds #}
81
+
case
82
+
when is_anomalous = TRUE and'{{ test_configuration.anomaly_direction }}'='spike' then
83
+
lag(metric_value) over (partition by full_table_name, column_name, metric_name, dimension, dimension_value, bucket_seasonality order by bucket_end)
84
+
when is_anomalous = TRUE and'{{ test_configuration.anomaly_direction }}'!='spike' then
85
+
lag(min_metric_value) over (partition by full_table_name, column_name, metric_name, dimension, dimension_value, bucket_seasonality order by bucket_end)
86
+
when '{{ test_configuration.anomaly_direction }}'='spike' then metric_value
87
+
else min_metric_value
88
+
end as min_value,
89
+
case
90
+
when is_anomalous = TRUE and'{{ test_configuration.anomaly_direction }}'='drop' then
91
+
lag(metric_value) over (partition by full_table_name, column_name, metric_name, dimension, dimension_value, bucket_seasonality order by bucket_end)
92
+
when is_anomalous = TRUE and'{{ test_configuration.anomaly_direction }}'!='drop' then
93
+
lag(max_metric_value) over (partition by full_table_name, column_name, metric_name, dimension, dimension_value, bucket_seasonality order by bucket_end)
94
+
when '{{ test_configuration.anomaly_direction }}'='drop' then metric_value
{# when there is an anomaly we would want to use the last value of the metric (lag), otherwise visually the expectations would look out of bounds #}
111
+
case
112
+
when is_anomalous = TRUE and'{{ test_configuration.anomaly_direction }}'='spike' then
113
+
lagInFrame(metric_value, 1) over (partition by full_table_name, column_name, metric_name, dimension, dimension_value, bucket_seasonality order by bucket_end)
114
+
when is_anomalous = TRUE and'{{ test_configuration.anomaly_direction }}'!='spike' then
115
+
lagInFrame(min_metric_value, 1) over (partition by full_table_name, column_name, metric_name, dimension, dimension_value, bucket_seasonality order by bucket_end)
116
+
when '{{ test_configuration.anomaly_direction }}'='spike' then metric_value
117
+
else min_metric_value
118
+
end as min_value,
119
+
case
120
+
when is_anomalous = TRUE and'{{ test_configuration.anomaly_direction }}'='drop' then
121
+
lagInFrame(metric_value, 1) over (partition by full_table_name, column_name, metric_name, dimension, dimension_value, bucket_seasonality order by bucket_end)
122
+
when is_anomalous = TRUE and'{{ test_configuration.anomaly_direction }}'!='drop' then
123
+
lagInFrame(max_metric_value, 1) over (partition by full_table_name, column_name, metric_name, dimension, dimension_value, bucket_seasonality order by bucket_end)
124
+
when '{{ test_configuration.anomaly_direction }}'='drop' then metric_value
0 commit comments