-
Notifications
You must be signed in to change notification settings - Fork 577
Description
A subselect clause under an optional clause fails in RDFlib. Let us consider the following example:
prefix ex: <https://www.example.org/>
ex:document ex:subject "Nice cars" .
ex:someCar ex:type "Car" .
I want to be able to query this graph and put all cars in some document about cars, if there are any cars. I use a subselect clause under an optional clause. The real reason for the subselect is that I want to count the number of cars (optionally being zero), but that is not relevant here. The example code is simple, does not involve an aggregate, but fails to yield the correct results.
prefix ex: <https://www.example.org/>
select ?subject ?car
where {
$this ex:subject ?subject.
# optional clause
optional
{
# an offending subselect clause
select ?car
where {
?car ex:type "Car".
}
}
}
I would expect the following results:
subject: "Nice cars"
car: https://www.example.org/someCar
Instead I get:
subject: None
car: https://www.example.org/someCar
So the variable subject is incorrectly not bound in the result set.
If I would query with the optional clause and an ordinary triple pattern without a subselect clause, then I get the results I want:
prefix ex: <https://www.example.org/>
select ?subject ?car
where {
$this ex:subject ?subject.
# optional clause
optional
{
# legit triple pattern without subselect
?car ex:type "Car".
}
}
Expected and achieved results:
subject: "Nice cars"
car: https://www.example.org/someCar
I have tested the offending subselect query under the following engines:
RDFlib, JENA, Speedy and Virtuoso. Only RDFlib results in the 'none' binding for subject, the three other engines show the expected results.