Skip to content

Commit 3958939

Browse files
committed
[refactor] Change the XQuery implementation defined behaviour for "Default order for empty sequences" to "empty least", so it matches the approach taken by Saxon and BaseX. IMHO "empty least" is also more likely the 'expected' behaviour.
1 parent e277048 commit 3958939

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

exist-core/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@
751751
<exclude>src/test/java/org/exist/xquery/value/SubSequenceRangeTest.java</exclude>
752752
<exclude>src/test/java/org/exist/xquery/value/SubSequenceTest.java</exclude>
753753
<exclude>src/test/xquery/binary-value.xqm</exclude>
754+
<exclude>src/test/xquery/order.xqm</exclude>
754755

755756
<!--
756757
Derivative work licensed under dbXML 1.0 and LGPL 2.1
@@ -901,6 +902,7 @@ The original license statement is also included below.]]></preamble>
901902
<include>src/test/java/org/exist/xquery/value/SubSequenceRangeTest.java</include>
902903
<include>src/test/java/org/exist/xquery/value/SubSequenceTest.java</include>
903904
<include>src/test/xquery/binary-value.xqm</include>
905+
<include>src/test/xquery/order.xqm</include>
904906
</includes>
905907

906908
</licenseSet>

exist-core/src/main/java/org/exist/xquery/XQueryContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public class XQueryContext implements BinaryValueManager, Context {
320320
/**
321321
* Should empty order greatest or least?
322322
*/
323-
private boolean orderEmptyGreatest = true;
323+
private boolean orderEmptyGreatest = false;
324324

325325
/**
326326
* XQuery 3.0 - declare context item :=
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
(:
2+
: Copyright (C) 2014, Evolved Binary Ltd
3+
:
4+
: This file was originally ported from FusionDB to eXist-db by
5+
: Evolved Binary, for the benefit of the eXist-db Open Source community.
6+
: Only the ported code as it appears in this file, at the time that
7+
: it was contributed to eXist-db, was re-licensed under The GNU
8+
: Lesser General Public License v2.1 only for use in eXist-db.
9+
:
10+
: This license grant applies only to a snapshot of the code as it
11+
: appeared when ported, it does not offer or infer any rights to either
12+
: updates of this source code or access to the original source code.
13+
:
14+
: The GNU Lesser General Public License v2.1 only license follows.
15+
:
16+
: ---------------------------------------------------------------------
17+
:
18+
: Copyright (C) 2014, Evolved Binary Ltd
19+
:
20+
: This library is free software; you can redistribute it and/or
21+
: modify it under the terms of the GNU Lesser General Public
22+
: License as published by the Free Software Foundation; version 2.1.
23+
:
24+
: This library is distributed in the hope that it will be useful,
25+
: but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27+
: Lesser General Public License for more details.
28+
:
29+
: You should have received a copy of the GNU Lesser General Public
30+
: License along with this library; if not, write to the Free Software
31+
: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32+
:)
33+
xquery version "1.0";
34+
35+
module namespace ord = "http://exist-db.org/test/order";
36+
37+
declare namespace test = "http://exist-db.org/xquery/xqsuite";
38+
39+
declare variable $ord:items as element(item)+ := (
40+
<item>
41+
<ref>e1</ref>
42+
<msDesc type="Ll"/>
43+
</item>
44+
,
45+
<item>
46+
<ref>e2</ref>
47+
<msDesc type="P"/>
48+
</item>
49+
,
50+
<item>
51+
<ref>e3</ref>
52+
<msDesc type="Ll"/>
53+
</item>
54+
,
55+
<item>
56+
<ref>e4</ref>
57+
<msDesc/>
58+
</item>
59+
);
60+
61+
declare
62+
%test:assertEquals("e2", "e1", "e3", "e4")
63+
function ord:default-order-for-empty-sequence-is-empty-least() {
64+
for $item in $ord:items
65+
let $sort-condition as xs:boolean? := $item/msDesc/@type eq 'P'
66+
order by $sort-condition descending
67+
return
68+
$item/ref/string()
69+
};
70+
71+
declare
72+
%test:assertEquals("e2", "e1", "e3", "e4")
73+
function ord:order-empty-sequence-as-empty-least() {
74+
for $item in $ord:items
75+
let $sort-condition as xs:boolean? := $item/msDesc/@type eq 'P'
76+
order by $sort-condition descending empty least
77+
return
78+
$item/ref/string()
79+
};
80+
81+
declare
82+
%test:assertEquals("e4", "e2", "e1", "e3")
83+
function ord:order-empty-sequence-as-empty-greatest() {
84+
for $item in $ord:items
85+
let $sort-condition as xs:boolean? := $item/msDesc/@type eq 'P'
86+
order by $sort-condition descending empty greatest
87+
return
88+
$item/ref/string()
89+
};

0 commit comments

Comments
 (0)