|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] Partitioning data by dateGhislain Fourny gfourny at inf.ethz.chThu May 20 12:11:48 PDT 2010
Hi Andrew,
If you are interested, with the tumbling windows Michael is mentioning (again, assuming your metrics are ordered by date) it could look like this:
<metrics>{
for tumbling window $w in doc("metricsCollection.xml")//metric
start at $s when fn:true()
end $m at $e next $n when
xs:date(xs:dateTime($m/timestamp)) ne xs:date(xs:dateTime($n/timestamp))
return
<metric>
<date>{xs:date(xs:dateTime($m/timestamp))}</date>
<num_actions>{$e - $s + 1}</num_actions>
</metric>
}</metrics>
Tumbling windows cannot overlap, so you can start one whenever it is possible, and end a window as soon as the date in an item $m is not the same as in the following item $n. $s and $e indicate the start and end positions of the current window.
You can test this query in Zorba (http://try.zorba-xquery.com).
Kind regards,
Ghislain
> One would also expect a solution using XQuery 1.1 "tumbling windows" to be O(n)
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






