Question

I'm currently trying to sort some clients by priority (those that have a running subscription first then the others.

To that effect I use a BIND clause in this query :

SELECT DISTINCT ?context ?priority ?label { 
    ?s a my:Client . 
    ?s rdfs:label ?label . 
    BIND ( IF(EXISTS {?s rdf:type my:Subscriber}, 1, 0)  AS ?priority ) 
} ORDER BY DESC(?priority) ASC(?label)

Seems to me that the ?priority var should always be bound to either 0 or 1 but whenever I execute the query I get (along with the expected output result) unbound ?priority "rows" for those items that should get 1 for priority so I need to add FILTER (bound(?priority)) in my query to get what i expect.

Is that normal or am I missing something ?

Thanks in advance, Max.

Edit :

=> filed the sort issue in the tracker

I edited the query to check that the prority is both bound and unbound on the same node.

Here's a sample output of the resultset I get back

?context = urn:graph:1772#844 , ?priority = 1^^http://www.w3.org/2001/XMLSchema#integer , ?sort1 = client 2@fr
?context = urn:graph:1772#1690 , ?priority = 1^^http://www.w3.org/2001/XMLSchema#integer , ?sort1 = client 1@fr
?context = urn:graph:1772#742 , ?priority = 0^^http://www.w3.org/2001/XMLSchema#integer , ?sort1 = client 4@fr
?context = urn:graph:1772#1010 , ?priority = 0^^http://www.w3.org/2001/XMLSchema#integer , ?sort1 = client 3@fr
?context = urn:graph:1772#1690 , ?sort1 = client 1@fr
?context = urn:graph:1772#844 , ?sort1 = client 2@fr

In the last two rows, the variable ?priority is not bound at all. By the way, you'll note that the second ORDER clause is also not honored if the first clause is unbound

Was it helpful?

Solution

There was a bug with the use of EXISTS as a child expression of another expression that could lead to incorrect results as in your example.

This is now fixed in the source code and will be included in the next release

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top