<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>6647</bug_id>
          
          <creation_ts>2009-03-03 12:53:40 +0000</creation_ts>
          <short_desc>[XQuery11UC] Windowing use case Q17: Invalid query</short_desc>
          <delta_ts>2009-04-28 13:00:48 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>XQuery 3.0 Use Cases</component>
          <version>Working drafts</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows XP</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.w3.org/TR/2008/WD-xquery-11-use-cases-20081203/#windowing_Q2_most_valuable_customer</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Wouter Cordewiner">wouter.cordewiner</reporter>
          <assigned_to name="Tim Kraska">tim</assigned_to>
          <cc>jim.melton</cc>
    
    <cc>marc.van.cappellen</cc>
    
    <cc>tim</cc>
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>24027</commentid>
    <comment_count>0</comment_count>
    <who name="Wouter Cordewiner">wouter.cordewiner</who>
    <bug_when>2009-03-03 12:53:40 +0000</bug_when>
    <thetext>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 &quot;end when newstart&quot; 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(&quot;cxml.xml&quot;);

&lt;result&gt;{
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
  &lt;mostValuableCustomer endOfDay=&quot;{xs:dateTime($cur/@date)}&quot;&gt;{
    let $companies :=   for $x in distinct-values($w/@billTo ) 
                        return &lt;amount company=&quot;{$x}&quot;&gt;{sum($w[@billTo eq $x]/@total)}&lt;/amount&gt;
    let $max := max($companies) 
    for $company in $companies
    where $company eq xs:untypedAtomic($max)
    return $company
  }&lt;/mostValuableCustomer&gt;
}&lt;/result&gt;

========================================</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>24095</commentid>
    <comment_count>1</comment_count>
    <who name="Tim Kraska">tim</who>
    <bug_when>2009-03-07 14:41:43 +0000</bug_when>
    <thetext>1) &quot;newstart&quot; 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, &quot;newstart&quot; 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
  &lt;mostValuableCustomer endOfDay=&quot;{xs:dateTime($cur/@date)}&quot;&gt;{
    let $companies :=	for $x in distinct-values($w/@billTo ) 
                        return &lt;amount company=&quot;{$x}&quot;&gt;{sum($w[@billTo eq $x]/@total)}&lt;/amount&gt;
    let $max := max($companies)	
    for $company in $companies
    where $company eq xs:untypedAtomic($max)
    return $company
  }&lt;/mostValuableCustomer&gt;
}&lt;/result&gt;
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>24105</commentid>
    <comment_count>2</comment_count>
    <who name="Wouter Cordewiner">wouter.cordewiner</who>
    <bug_when>2009-03-09 12:05:57 +0000</bug_when>
    <thetext>1. My point is, &quot;end when newstart&quot;, 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).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>24950</commentid>
    <comment_count>3</comment_count>
    <who name="Tim Kraska">tim</who>
    <bug_when>2009-04-28 13:00:18 +0000</bug_when>
    <thetext>You are right. The newstart keyword was dropped by the working group. </thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>