Query Details
// Notice that x = 15 does not have a state whose "parent step" is step 3 . But 11, 12, 13, 14, 16 do.
// This is because 14 had evaluated step 2 successfully, so in the next event (15) the state from step 2 will take precedence over the state from step 3, and this one will disappear.
let threshold = 5;
let _Range =
range x from 1 to 16 step 1
| extend ToBeCounted = not(x between (4 .. 6))
;
let _ScanResults =
_Range
| scan declare (ScanStep:long=0, ParentStep:long=0, Count:long=0, SurpassedThreshold:bool=false) with
(
step Step1: // output=none:
ToBeCounted
=> ScanStep = 1,
Count = Step1.Count + 1,
ParentStep = iff(Step1.Count == 0, int(null), 1)
;
step Step2:
ToBeCounted and Step1.Count >= threshold
=> ScanStep = 2,
Count = Step1.Count,
SurpassedThreshold = true,
ParentStep = iff(Step2.ParentStep == 0, 1, 2)
;
step Step3:
ToBeCounted and Step1.Count >= threshold
=> ScanStep = 3,
Count = Step2.Count,
SurpassedThreshold = true,
ParentStep = iff(Step3.ParentStep == 0, 2, 3)
;
)
;
_Range
| lookup _ScanResults on x, ToBeCounted
| sort by x asc, ScanStep asc
| project-reorder x, ToBeCounted, ScanStep, ParentStep
The query is analyzing a range of numbers from 1 to 16. The numbers 4, 5, and 6 are not included in the analysis. The query then performs a scan on the range, keeping track of various steps and their states.
In Step 1, the query counts the numbers that need to be counted and assigns a parent step value.
In Step 2, the query checks if the count from Step 1 is greater than or equal to a threshold value. If it is, the query updates the scan step, count, and sets a flag indicating that the threshold has been surpassed. The parent step value is also updated.
In Step 3, the query performs a similar check as Step 2, but with a different parent step value.
The results of the scan are then looked up and sorted based on the number and scan step. The final output includes the number, whether it needs to be counted, the scan step, and the parent step.

Jose Sebastián Canós
Released: October 17, 2022
Tables
Keywords
Operators