Skip to content

Instantly share code, notes, and snippets.

@fithisux
Last active January 21, 2026 14:52
Show Gist options
  • Select an option

  • Save fithisux/27a70810440571b777fb7a4afe367018 to your computer and use it in GitHub Desktop.

Select an option

Save fithisux/27a70810440571b777fb7a4afe367018 to your computer and use it in GitHub Desktop.
Proper detection
%sql
with annotated_data as (
SELECT
object_id,
sample_id,
feature_1,
lag(feature_1) OVER tracked_id_timeline as prev_feature_1,
feature_2,
lag(feature_2) OVER tracked_id_timeline prev_feature_2,
row_number() over tracked_id_timeline as rr
FROM
VALUES ('A1', 2, 1, 5), ('A1', 1, null, null), ('A2', 3, 3, 7), ('A1', 3, null, null) tab
(object_id, sample_id, feature_1, feature_2)
WINDOW tracked_id_timeline as (PARTITION BY object_id ORDER BY sample_id)
)
select
* except(rr, prev_feature_1, prev_feature_2)
from
annotated_data
where
rr = 1 or not (equal_null(feature_1, prev_feature_1) and equal_null(feature_2, prev_feature_2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment