<?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>26859</bug_id>
          
          <creation_ts>2014-09-19 14:29:04 +0000</creation_ts>
          <short_desc>orderBy63 may not test intended error conditions</short_desc>
          <delta_ts>2014-11-19 00:01:56 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XML Query Test Suite</product>
          <component>XML Query Test Suite</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></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="Josh Spiegel">josh.spiegel</reporter>
          <assigned_to name="O&apos;Neil Delpratt">oneil</assigned_to>
          <cc>mike</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>111803</commentid>
    <comment_count>0</comment_count>
    <who name="Josh Spiegel">josh.spiegel</who>
    <bug_when>2014-09-19 14:29:04 +0000</bug_when>
    <thetext>&lt;test-case name=&quot;orderBy63&quot; xmlns=&quot;http://www.w3.org/2010/09/qt-fots-catalog&quot;&gt;
      &lt;description&gt;Test that the context item for evaluating a sort key is NOT the item whose sort key is being computed&lt;/description&gt;
      &lt;created by=&quot;Michael Kay&quot; on=&quot;2011-07-30&quot;/&gt;
      &lt;environment ref=&quot;orderdata&quot;/&gt;
      &lt;dependency type=&quot;spec&quot; value=&quot;XQ10+&quot;/&gt;
      &lt;test&gt;&lt;![CDATA[
        declare default element namespace &quot;http://www.w3.org/XQueryTestOrderBy&quot;; 
        /DataValues/(
            for $x in NegativeNumbers/orderData
            order by xs:decimal(.)
            return $x)]]&gt;&lt;/test&gt;
      &lt;result&gt;
         &lt;any-of&gt;
            &lt;error code=&quot;FOTY0004&quot;/&gt;
            &lt;error code=&quot;FOTY0012&quot;/&gt;
            &lt;error code=&quot;FORG0001&quot;/&gt;
         &lt;/any-of&gt;
      &lt;/result&gt;
&lt;/test-case&gt;

Some implementations may be able to compute the result of this query without evaluating the order by clause, thereby avoiding the error condition (which is allowed under 2.3.4 Errors and Optimization).  I would like to modify the query to force the order by clause to be relevant to the result.  For example:

        declare default element namespace &quot;http://www.w3.org/XQueryTestOrderBy&quot;; 
        /DataValues/(
            (
            for $x at $pos in NegativeNumbers/orderData
            order by xs:decimal(.) + $pos
            return $x
            )[1]
        )</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>114925</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2014-11-14 10:00:47 +0000</bug_when>
    <thetext>I don&apos;t think the proposed change helps much. An implementation can still determine that xs:decimal(.) contributes nothing to the sorting. A better fix would be one where the test is made error-free. Perhaps 

/DataValues/(
            for $x in NegativeNumbers/*
            order by (if name(.) = &apos;orderData&apos; then $x else -$x)
            return $x)

which produces different results depending on the context item used to evaluate name(.).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>114938</commentid>
    <comment_count>2</comment_count>
    <who name="Josh Spiegel">josh.spiegel</who>
    <bug_when>2014-11-14 16:45:07 +0000</bug_when>
    <thetext>The results of the path expression should be in document order so the order by can still be eliminated in your version.

What about this:

  /DataValues/(
    (
      for $x in NegativeNumbers/*
      order by (if (name(.) = &apos;orderData&apos;) then $x else -$x)
      return $x
    )[1]
  )

With expected result:

  &lt;orderData xmlns=&quot;http://www.w3.org/XQueryTestOrderBy&quot;&gt;-0&lt;/orderData&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>114940</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2014-11-14 18:30:20 +0000</bug_when>
    <thetext>I missed the document order problem: could solve that by using &quot;!&quot; instead of &quot;/&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>114944</commentid>
    <comment_count>4</comment_count>
    <who name="Josh Spiegel">josh.spiegel</who>
    <bug_when>2014-11-14 18:55:39 +0000</bug_when>
    <thetext>I think that would work as well except currently it is a 1.0 test.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115082</commentid>
    <comment_count>5</comment_count>
    <who name="Josh Spiegel">josh.spiegel</who>
    <bug_when>2014-11-19 00:01:56 +0000</bug_when>
    <thetext>I applied the fix in Comment 2 since it appears to achieve the goal of the test without restricting it to 3.0+.  Please reopen if you see a problem with this.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>