Skip to content

Instantly share code, notes, and snippets.

@seandavi
Created November 13, 2025 12:34
Show Gist options
  • Select an option

  • Save seandavi/5b072d72f8adef1f237fad67368ae5db to your computer and use it in GitHub Desktop.

Select an option

Save seandavi/5b072d72f8adef1f237fad67368ae5db to your computer and use it in GitHub Desktop.
bioc build database islands-and-gaps
/* 1. give every row a sequence number */
WITH ordered AS (
SELECT
package,
stage,
status,
startedat,
row_number() OVER (PARTITION BY package ORDER BY startedat) AS rn
FROM t_build_summary where stage='buildsrc'
),
/* 2. flag the rows where (stage,status) changes */
with_change AS (
SELECT
*,
CASE
WHEN stage = lag(stage) OVER (PARTITION BY package ORDER BY rn)
AND status = lag(status) OVER (PARTITION BY package ORDER BY rn)
THEN 0
ELSE 1
END AS is_new_group
FROM ordered
),
/* 3. build the island identifier (running sum of the flag) */
grouped AS (
SELECT
*,
sum(is_new_group) OVER (PARTITION BY package ORDER BY rn) AS island_id
FROM with_change
)
/* 4. collapse each island to one row */
SELECT
package,
stage,
status,
min(startedat) AS start_ts,
max(startedat) AS end_ts
FROM grouped where package='MAGeCKFlute'
GROUP BY package, island_id, stage, status
ORDER BY package, start_ts DESC;
package stage status start_ts end_ts
MAGeCKFlute buildsrc ERROR 2025-08-19 03:41:10-04 2025-10-15 18:16:20-04
MAGeCKFlute buildsrc TIMEOUT 2025-08-18 21:56:21-04 2025-08-18 21:56:21-04
MAGeCKFlute buildsrc ERROR 2024-12-30 17:42:54-05 2025-08-18 20:54:28-04
MAGeCKFlute buildsrc OK 2024-04-24 17:48:15-04 2024-10-17 03:24:57-04
MAGeCKFlute buildsrc ERROR 2024-04-24 17:24:12-04 2024-04-24 17:24:12-04
MAGeCKFlute buildsrc OK 2024-03-22 17:10:45-04 2024-04-24 17:15:29-04
MAGeCKFlute buildsrc ERROR 2024-03-21 20:30:44-04 2024-03-21 20:30:44-04
MAGeCKFlute buildsrc OK 2024-03-20 19:21:50-04 2024-03-21 20:00:15-04
MAGeCKFlute buildsrc ERROR 2024-03-20 19:19:50-04 2024-03-20 19:19:50-04
MAGeCKFlute buildsrc OK 2024-03-09 21:34:32-05 2024-03-20 17:49:10-04
MAGeCKFlute buildsrc TIMEOUT 2024-03-08 20:06:10-05 2024-03-08 20:06:10-05
MAGeCKFlute buildsrc OK 2024-03-08 17:06:48-05 2024-03-08 19:53:33-05
MAGeCKFlute buildsrc ERROR 2024-03-07 19:56:34-05 2024-03-07 19:56:34-05
MAGeCKFlute buildsrc OK 2024-03-06 17:41:41-05 2024-03-07 18:50:40-05
MAGeCKFlute buildsrc ERROR 2024-03-06 17:01:27-05 2024-03-06 17:01:27-05
MAGeCKFlute buildsrc OK 2024-03-05 17:47:11-05 2024-03-05 20:48:52-05
MAGeCKFlute buildsrc ERROR 2024-03-04 23:24:34-05 2024-03-04 23:24:34-05
MAGeCKFlute buildsrc TIMEOUT 2024-03-04 20:35:22-05 2024-03-04 20:35:22-05
MAGeCKFlute buildsrc OK 2024-02-29 17:12:16-05 2024-03-04 20:26:15-05
MAGeCKFlute buildsrc TIMEOUT 2024-02-29 07:21:29-05 2024-02-29 07:21:29-05
MAGeCKFlute buildsrc OK 2024-02-28 21:32:24-05 2024-02-28 21:32:24-05
MAGeCKFlute buildsrc TIMEOUT 2024-02-28 20:36:22-05 2024-02-28 20:36:22-05
MAGeCKFlute buildsrc OK 2021-10-14 07:37:19-04 2024-02-28 20:09:41-05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment