This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
In XQuery 1.1 Use Cases, Working Draft 3 December 2008 the windowing use case Q17 have query errors: 1. The window end condition is missing, ie "end when newstart" is not appropriate for this query I think. 2. day-from-date(xs:dateTime($cur/@date)) is not correct as a xs:dateTime value is provided where day-from-date() expects a xs:date(). Correcting both issues, I believe the corrected query should be (adhering to the expected results): ======================================== declare variable $seq := fn:doc("cxml.xml"); <result>{ for sliding window $w in $seq/sequence/* start $cur previous $prev when day-from-dateTime(xs:dateTime($cur/@date)) ne day-from-dateTime(xs:dateTime($prev/@date)) or empty($prev) end $end next $next when day-from-dateTime(xs:dateTime($end/@date)) ne day-from-dateTime(xs:dateTime($next/@date)) return <mostValuableCustomer endOfDay="{xs:dateTime($cur/@date)}">{ let $companies := for $x in distinct-values($w/@billTo ) return <amount company="{$x}">{sum($w[@billTo eq $x]/@total)}</amount> let $max := max($companies) for $company in $companies where $company eq xs:untypedAtomic($max) return $company }</mostValuableCustomer> }</result> ========================================
1) "newstart" defines a tumbling window which opens a new window in the moment the start condition is fullfiled. Here the start condition defines the beginning of a new day and thus the end of the previous day. Hence, "newstart" should be correct. 2) I agree, it has to be day-from-dateTime. Additionally, the explicit cast could be avoided since the XML-Schema for Q17 already states that the attribute is of the type type xs:dateTime. However, I leave it as it is for the moment. The query with the day-from-dateTime change would be: for tumbling window $w in $seq/sequence/* start $cur previous $prev when day-from-dateTime(xs:dateTime($cur/@date)) ne day-from-dateTime(xs:dateTime($prev/@date)) or empty($prev) end when newstart return <mostValuableCustomer endOfDay="{xs:dateTime($cur/@date)}">{ let $companies := for $x in distinct-values($w/@billTo ) return <amount company="{$x}">{sum($w[@billTo eq $x]/@total)}</amount> let $max := max($companies) for $company in $companies where $company eq xs:untypedAtomic($max) return $company }</mostValuableCustomer> }</result>
1. My point is, "end when newstart", is newstart a variable? If so, it should be $newstart and should be declared somewhere? Is it a path evaluation? If so, to which context is it evaluated? Nowhere in the query and/or cxml.xml is there a reference to newstart. Again, this is based on XQuery 1.1 Use Cases, Working Draft 3 December 2008 (http://www.w3.org/TR/2008/WD-xquery-11-use-cases-20081203/#windowing_Q2_most_valuable_customer).
You are right. The newstart keyword was dropped by the working group.