@@ -34,16 +34,22 @@ on {{ split_and_return_nth_value('table_name', '.', 1) }} = m.database
3434and {{ split_and_return_nth_value(' table_name' , ' .' , 2 ) }} = m .schema
3535and {{ split_and_return_nth_value(' table_name' , ' .' , 3 ) }} = m .name
3636where
37- case
38- when {{ json_extract(' m.anomaly_detector' , ' name' ) }} = ' z_score'
39- then abs(z_score_value) > cast({{ json_extract(' m.anomaly_detector' , ' threshold' ) }} as {{ numeric_type() }})
40- when {{ json_extract(' m.anomaly_detector' , ' name' ) }} = ' modified_z_score'
41- then abs(modified_z_score_value) > cast( {{ json_extract(' m.anomaly_detector' , ' threshold' ) }} as {{numeric_type()}} )
42- when {{ json_extract(' m.anomaly_detector' , ' name' ) }} = ' boxplot'
43- then (
44- z .last_value < z .last_first_quartile - (cast( {{ json_extract(' m.anomaly_detector' , ' whisker_boundary_multiplier' ) }} as {{numeric_type()}} ) * z .last_iqr )
45- or
46- z .last_value > z .last_third_quartile + (cast( {{ json_extract(' m.anomaly_detector' , ' whisker_boundary_multiplier' ) }} as {{numeric_type()}} ) * z .last_iqr )
47- )
37+ case when (lower (coalesce({{ json_extract(' m.anomaly_detector' , ' direction' ) }}, ' both' )) = ' up' and z .last_value > z .last_avg )
38+ or (lower (coalesce({{ json_extract(' m.anomaly_detector' , ' direction' ) }}, ' both' )) = ' down' and z .last_value < z .last_avg )
39+ or (lower (coalesce({{ json_extract(' m.anomaly_detector' , ' direction' ) }}, ' both' )) != ' up' and lower (coalesce({{ json_extract(' m.anomaly_detector' , ' direction' ) }}, ' both' )) != ' down' )
40+ then
41+ case
42+ when {{ json_extract(' m.anomaly_detector' , ' name' ) }} = ' z_score'
43+ then abs(z_score_value) > cast({{ json_extract(' m.anomaly_detector' , ' threshold' ) }} as {{ numeric_type() }})
44+ when {{ json_extract(' m.anomaly_detector' , ' name' ) }} = ' modified_z_score'
45+ then abs(modified_z_score_value) > cast( {{ json_extract(' m.anomaly_detector' , ' threshold' ) }} as {{numeric_type()}} )
46+ when {{ json_extract(' m.anomaly_detector' , ' name' ) }} = ' boxplot'
47+ then (
48+ z .last_value < z .last_first_quartile - (cast( {{ json_extract(' m.anomaly_detector' , ' whisker_boundary_multiplier' ) }} as {{numeric_type()}} ) * z .last_iqr )
49+ or
50+ z .last_value > z .last_third_quartile + (cast( {{ json_extract(' m.anomaly_detector' , ' whisker_boundary_multiplier' ) }} as {{numeric_type()}} ) * z .last_iqr )
51+ )
52+ else false
53+ end
4854 else false
4955 end
0 commit comments