Problem description
Variable scope semantics (see SPARQL 1.1 Query language specification) seems to be violated in the presence of sub-select and optionals.
Reproduction steps
Given the following dataset:
INSERT DATA {
GRAPH <urn:test:graph> {
<urn:test:s> <urn:test:p> <urn:test:o> .
<urn:test:x> <urn:test:y> <urn:test:z> .
}
}
the following query:
SELECT DISTINCT ?s ?unbound ?unexpectedResult
WHERE
{ {
SELECT DISTINCT ?s ?unbound
WHERE {
?s <urn:test:p> ?o .
OPTIONAL {?s <urn:whatever:DoesNotExist> ?unbound }
} LIMIT 1
}
OPTIONAL { ?unbound ?someProperty ?unexpectedResult . }
}
leads to this results:
s,unbound,unexpectedResult
urn:test:s,urn:test:s,urn:test:o
urn:test:s,urn:test:x,urn:test:z
Expected behavior
The documented query should lead to this results:
s,unbound,unexpectedResult
urn:test:s,,
according to my understanding of the variable scope specification.
Is this correct? Or am I missing something?