for tumbling window $w in (2, 4, 6, 8, 10, 12, 14)
start at $s when fn:true()
only end at $e when $e - $s eq 2
return <window>{ $w }</window>
Result of the above query:
<window>2 4 6</window>
<window>8 10 12</window>
Can someone explain why is it <2 4 6>, <8 10 12> ? Why only 3 values <2 4 6>, <8 10 12>, and how is it working to get 2 4 6, or 8 10 12 ?
The example
for tumbling window $w in (2, 4, 6, 8, 10, 12, 14)
start at $s when fn:true()
only end at $e when $e - $s eq 2
return <window>{ $w }</window>
seems to be taken directly from the spec https://www.w3.org/TR/xquery-30/#id-tumbling-windows and that has some good explanation of the result:
Windows are created by iterating over the items in the binding sequence, in order, identifying the start item and the end item of each window by evaluating the WindowStartCondition and the WindowEndCondition. Each of these conditions is satisfied if the effective boolean value of the expression following the when keyword is true. The start item of the window is an item that satisfies the WindowStartCondition (see 3.10.4.1 Tumbling Windows and 3.10.4.2 Sliding Windows for a more complete explanation.) The end item of the window is the first item in the binding sequence, beginning with the start item, that satisfies the WindowEndCondition (again, see 3.10.4.1 Tumbling Windows and 3.10.4.2 Sliding Windows for more details.) Each window contains its start item, its end item, and all items that occur between them in the binding sequence.
If the window type is tumbling, then windows never overlap. The search for the start of the first window begins at the beginning of the binding sequence. After each window is generated, the search for the start of the next window begins with the item in the binding sequence that occurs after the ending item of the last generated window. Thus, no item that occurs in one window can occur in another window drawn from the same binding sequence (unless the sequence contains the same item more than once).
So with the binding sequence being 2, 4, 6, 8, 10, 12, 14 the variables defined using start at $s and only end at $e are positional:
Start-item-position: (Optional) Bound to the ordinal position of the first window item in the binding sequence. Start-item-position is a positional variable; hence, its type is xs:integer End-item-position: (Optional) Bound to the ordinal position of the last window item in the binding sequence. End-item-position is a positional variable; hence, its type is xs:integer
and for the first item 2 and the third item 6 the positional values 3 - 1 are 2 so the first window contains 2, 4, 6, then the search for a new window starts with 8 at position 4 and ends with 12 at position 6 as 6 - 4 is also 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With