Files
dbt-f2dq/macros/public/store/export_alerts.sql
T
M7XBeastandCursor ff096b51b5 Initial publish of dbt_f2dq (f2dq) package v0.12.1.
Clean package repo for Gitea installs via packages.yml git URL.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-11 17:37:40 +03:00

23 lines
1011 B
SQL

{% macro export_alerts(start_date, end_date, alerts_path=None, monitored_path=None) %}
{% set alerts_query %}
select
type as {{ f2dq.quote_column('type') }},
model as {{ f2dq.quote_column('model') }},
message as {{ f2dq.quote_column('message') }},
value as {{ f2dq.quote_column('value') }},
{{ format_timestamp('time_window_end')}} as {{ f2dq.quote_column('time_window_end') }}
from {{ ref('f2dq_alerts') }}
where
case
when type = 'anomaly' then {{ in_date_window('time_window_end', start_date, end_date) }}
else {{ in_date_window('time_window_end', start_date, none) }}
end
order by time_window_end desc
{% endset %}
{% set query_result = run_query(alerts_query) %}
{% set alerts_file_path = alerts_path or 'target/f2dq/alerts.json' %}
{% do query_result.to_json(alerts_file_path) %}
{{ save_monitored(monitored_path) }}
{% endmacro %}