This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 6647 - [XQuery11UC] Windowing use case Q17: Invalid query
Summary: [XQuery11UC] Windowing use case Q17: Invalid query
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XQuery 3.0 Use Cases (show other bugs)
Version: Working drafts
Hardware: PC Windows XP
: P2 normal
Target Milestone: ---
Assignee: Tim Kraska
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL: http://www.w3.org/TR/2008/WD-xquery-1...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-03 12:53 UTC by Wouter Cordewiner
Modified: 2009-04-28 13:00 UTC (History)
3 users (show)

See Also:


Attachments

Description Wouter Cordewiner 2009-03-03 12:53:40 UTC
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>

========================================
Comment 1 Tim Kraska 2009-03-07 14:41:43 UTC
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>
Comment 2 Wouter Cordewiner 2009-03-09 12:05:57 UTC
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).
Comment 3 Tim Kraska 2009-04-28 13:00:18 UTC
You are right. The newstart keyword was dropped by the working group.