Write a function to identify anomalies and missing data points across distributed event streams without writing inefficient or unindexed queries.
Use the provided stream definitions and event records over the parameterized monitoring interval. Return every expected point that is missing or anomalous, while excluding inactive streams and events outside the interval.
stream_id, expected_at, anomaly_type, event_count, first_event_at, and last_event_at.missing, duplicate, null_value, or out_of_range anomalies, ordered by stream_id, expected_at, and anomaly_type.| Column | Type | Description |
|---|---|---|
| stream_idPK | VARCHAR(40) | Unique event stream identifier |
| source_region | VARCHAR(30) | Region producing the stream |
| expected_interval_seconds | INT | Expected interval between data points |
| minimum_value | DECIMAL(10,2) | Allowed minimum event value |
| maximum_value | DECIMAL(10,2) | Allowed maximum event value |
| is_active | BOOLEAN | Whether the stream should be monitored |
| Column | Type | Description |
|---|---|---|
| event_idPK | BIGINT | Unique event identifier |
| stream_id | VARCHAR(40) | Referenced event stream |
| event_time | TIMESTAMPTZ | Time at which the event was received |
| event_type | VARCHAR(30) | Event classification |
| event_value | DECIMAL(10,2) | Measured event value |