Given a database schema and documentation, implement functions on the spot using the documentation.
Asked in the learning stage. VO2; repeated in the HM technical portion.
Implement the documented PostgreSQL function get_pipeline_health(workspace_id, month_start). Return one row for every active pipeline in the workspace. Include only runs from month_start through the final day of that month. A pipeline with no runs must still appear. failure_rate_pct is failed runs divided by all runs, rounded to two decimal places. Health is no runs for zero runs, healthy for a failure rate at most 10%, and attention otherwise.
pipeline_id, pipeline_name, total_runs, successful_runs, failure_rate_pct, health_statuspipeline_name ascendingUse the documented function contract and schema below.
| Column | Type | Description |
|---|---|---|
| workspace_idPK | INT | Unique workspace identifier |
| workspace_name | VARCHAR(100) | Workspace display name |
| Column | Type | Description |
|---|---|---|
| pipeline_idPK | INT | Unique pipeline identifier |
| workspace_id | INT | Workspace containing the pipeline |
| pipeline_name | VARCHAR(120) | Pipeline display name |
| owner_team | VARCHAR(100) | Team responsible for the pipeline |
| is_active | BOOLEAN | Whether the pipeline should be included |
| Column | Type | Description |
|---|---|---|
| run_idPK | INT | Unique pipeline run identifier |
| pipeline_id | INT | Pipeline executed by the run |
| run_started_at | TIMESTAMP | Run start timestamp |
| status | VARCHAR(20) | Run outcome, normally success or failure |