Interactive engineering lab

Gaps and islands: consecutive runs, duplicates and a tolerance

Gaps and islands: consecutive runs, duplicates and a tolerance. Step through four SQL methods with repeated days, local days and partitions.

By Sandeep Belgavi · Published 2026-11-11

Synthetic fixtures computed locally. No model, skill registry, database or production service is contacted.

Experiment workspace

Decision trace

    The question this experiment answers

    Hansini reports how many consecutive days each help-desk queue at Belgavi's Book Store had activity. The standard SQL answer subtracts a row number from the day and groups by the difference: within a run of consecutive days the difference is constant. This lab generates a seeded event table and shows, row by row, which island each row joins under four methods, and what happens when a day has two rows, when the activity day is local rather than UTC, when queues are not partitioned and when a missing day should be tolerated.

    Change one assumption at a time

    Start from one_row_per_day: every method agrees with the reference. Raise Chance of a second row that day to 0.3: ROW_NUMBER over raw rows now splits and merges runs wrongly, while DENSE_RANK and DISTINCT stay correct. Set the UTC offset to 330 minutes and the late share to 0.3: rows near midnight move to the next day and the islands change. Add a second queue and switch Partition by queue to No. Finally choose the LAG method and tolerate one missing day.

    Expected outcomes

    one_row_per_day: 22 rows, 7 islands, longest run 6 days, matching the reference. duplicates_row_number: 4 rows repeat a day; 9 islands of which 5 are wrong, and the longest run reads 13 days against a true 5. duplicates_dense_rank and duplicates_distinct: correct. tolerance_one_day: 2 islands, longest 22 days. local_day_offset: 8 rows change day, 9 reference islands by local day against 7 by UTC day. two_queues_partitioned: 15 islands, correct. two_queues_not_partitioned: 5 islands against 15. sparse_quarter: 19 islands, longest 4 days.

    Read the table and the trace

    The metrics count rows, rows that repeat a day, rows whose local day differs from their UTC day, islands found and in the reference, wrong and missed islands, the longest run found and in the reference, and the island count if days were UTC. The table lists each island the selected method found with its span, active days, rows and whether it matches the reference. The trace walks the rows in SQL order with the rank or start flag, the island key and the island number.

    Reset and export

    Reset inputs restores the selected preset and recomputes. Export JSON downloads the inputs, every island, every trace step, the metrics and the stated limits.

    Limits

    One synthetic event stream per queue with a fixed UTC offset, so no daylight-saving changes, which need a time zone database, and no late-arriving rows. The model reproduces what the SQL statements compute, checked against SQLite in the companion example; it does not model query performance, indexes or very large tables.

    Views are my own and do not represent any employer, past or present.