We're updating the issue view to help you get more done. 

VALUES in OPTIONAL returns incorrect query results

Description

Reported on the mailinglist by Drew Perttula:

I want to sort results by the presence of a class:

1 2 3 4 5 6 7 8 9 10 11 SELECT DISTINCT ?comp ?label ?isServiceComponent WHERE { ?project jira:component ?comp . ?comp rdfs:label ?label . OPTIONAL { ?comp a :ServiceComponent . VALUES (?isServiceComponent) { (:ServiceComponent ) } } } ORDER BY ?isServiceComponent

I stumbled on VALUES, but I welcome other suggestions for how to accomplish my query. Meanwhile, this query seems to reveal a bug in VALUES.

Without the VALUES block in there, I get rows with ?comp and ?label, and of course ?isServiceComponent is always undef. All rows are returned. This seems correct.

With the query as written above, a few things go wrong at once: all ?label results become undefined, and rows with no ?isServiceComponent are omitted, like this:

1 2 3 4 5 ?comp ?label ?isServiceComponent --------- --------- ----------------------------- comp:1 :ServiceComponent comp:3 :ServiceComponent comp:5 :ServiceComponent

It's kind of like the rdfs:label constraint and the OPTIONAL keyword both got ignored, turning the '?comp a :ServiceComponent' pattern from optional to required and turning the VALUES into something that's always applied.

Environment

None

Status

Assignee

JeenB

Reporter

JeenB

Labels

None

Fix versions

Affects versions

2.6.10

Priority

Major