gpt4 book ai didi

XQUERY 滚动窗口

转载 作者:行者123 更新时间:2023-12-04 02:08:53 26 4
gpt4 key购买 nike

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>

上述查询的结果:

<window>2 4 6</window>
<window>8 10 12</window>

有人可以解释为什么是 <2 4 6>, <8 10 12> 吗?为什么只有 3 个值 <2 4 6>、<8 10 12>,如何得到 2 4 6 或 8 10 12?

最佳答案

例子

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>

似乎直接取自规范 https://www.w3.org/TR/xquery-30/#id-tumbling-windows这对结果有一些很好的解释:

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).

因此绑定(bind)序列为 2, 4, 6, 8, 10, 12, 14 使用 start at $sonly end 定义的变量在 $e 位置:

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

对于第一项 2 和第三项 6,位置值 3 - 12所以第一个窗口包含 2, 4, 6,然后搜索新窗口从位置 4 处的 8 开始,以 结束>12 在位置 6 因为 6 - 4 也是 2

关于XQUERY 滚动窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40726182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com