Skip to content
Advertisement

Output number of non-consecutive failures from historical data in Bigquery

this is related to my previous scenario.

I have a dataset like this:

Aside from outputting the timestamp in which a user first committed a failure, and consecutively commits a failure status every day, leading up to today (2022-04-29), I also want to output the non-consecutive block of days in which Karl or Andrea commits a failure.

In this case, Andrea started failing recently at 2022-04-25 4:00:00 and commits 3 failure blocks (03-15, 03-28 to 03-30, 04-25 to 04-28) while Karl started failing recently at 2022-04-27 4:00:00 and commits 2 failure blocks (03-28, 04-27 to 04-28).

Final output should be

name status started recently failing timestamp recent days failing total days failing total failure blocks
Andrea Failure 2022-04-25 4:00:00 4 8 3
Karl Failure 2022-04-27 4:00:00 2 3 2

Thank you for those who can help, I really would appreciate it.

Advertisement

Answer

Take a look at below query although it’s not refined yet. Hoping help you find some clue to approach your problem.

  1. failure_blocks is for figuring out each consecutive failing days.
  2. last_blocks is for finding last failing block to identify started_recently_failing_timestamp
  3. Main query generates the expected output from previous CTEs.

enter image description here

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement