History | Log In     View a printable version of the current page. Get help!  
Issue Details [XML]

Key: SES-630
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: James Leigh
Reporter: Damyan Ognyanoff
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Sesame

Incorrect query result ordering when optional statement pattern variables are involved

Created: 30/Oct/08 11:44 AM   Updated: 17/Dec/08 02:05 PM
Component/s: Query Engine
Affects Version/s: 2.2.1, 2.1.4, 2.2, 2.1.3, 2.1.2, 2.1.1, 2.1, 2.0.1, 2.0
Fix Version/s: 2.2.2


 Description   
We observed some strange behavior on a sparql query involving 'order by' over a variable which is used in a OPTIONAL statement pattern - in such case the result is not ordered.

The query is:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?a ?label
WHERE {
   ?a rdf:type <http://www.w3.org/2002/07/owl#Thing> .
   OPTIONAL {?a rdfs:label ?label }
}
ORDER BY ?label

the sample data :
<?xml version="1.0"?>
<rdf:RDF
  xmlns="http://TestSort#"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  xmlns:owl="http://www.w3.org/2002/07/owl#"
xml:base="http://TestSort">
<owl:Ontology rdf:about="">
  <owl:versionInfo rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Created with TopBraid Composer</owl:versionInfo>
</owl:Ontology>
<owl:Thing rdf:ID="Thing_1"/>
<owl:Thing rdf:ID="Thing_3"/>
<owl:Thing rdf:ID="Thing_5"/>
<owl:Thing rdf:ID="Thing_0">
  <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Thing_6</rdfs:label>
</owl:Thing>
<owl:Thing rdf:ID="Thing_7"/>
<owl:Thing rdf:ID="Thing_2">
  <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Thing_2</rdfs:label>
</owl:Thing>
<owl:Thing rdf:ID="Thing_4">
  <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Thing_4</rdfs:label>
</owl:Thing>
</rdf:RDF>

and the output:
http://TestSort#Thing_1
http://TestSort#Thing_3
http://TestSort#Thing_5
http://TestSort#Thing_0 "Thing_6"^^http://www.w3.org/2001/XMLSchema#string
http://TestSort#Thing_7
http://TestSort#Thing_2 "Thing_2"^^http://www.w3.org/2001/XMLSchema#string
http://TestSort#Thing_4 "Thing_4"^^http://www.w3.org/2001/XMLSchema#string


 All   Comments   Change History      Sort Order:
Comment by Arjohn Kampman [30/Oct/08 11:47 AM]
When Var is not bound it is evaluated to throw a
ValueExprEvaluationException. The OrderComparator catches
QueryEvaluationException (or StoreException) and assumes that anything
that cannot be evaluated is the same as everything else. This results in
the sort method to conclude that all values are equal and no further
ordering is needed.

I changed the OrderComparator in trunk and 2.2 branch to catch
QueryEvaluationException and treat that as a null value. This results in
the expected order.