This test tries to show what happens during variable substitution when an EXISTS filter pattern with a sub-query is evaluated. The results from running it under both ARQ and RDF::Query contradict my understanding of how SPARQL filter and EXISTS evaluation are meant to occur.
<x> <seq> 2 ;
<even> 2, 4 .
<y> <seq> 5 ;
<even> 2, 4, 6 .
# Find all ?s that have a <seq> value that is equal to the
# number of <even> values belonging to that ?s
SELECT ?s WHERE {
?s <seq> ?value .
FILTER EXISTS {
?s <seq> ?count
{
SELECT (COUNT(*) AS ?count) WHERE {
?s <even> ?other
}
}
}
}
Based on variable substitution for EXISTS, I expect both appearances of ?s
in the EXISTS
pattern to be replaced during filtering. However, the results from existing implementations seems to confict with this interpretation, instead indicating that they are evaluating the aggregation without variable substitution (getting a ?count
value of 5
instead of 2
and 3
(for ?s=<x>
and ?s=<y>
, respectively).
-------
| s |
=======
| <x> |
-------
-------
| s |
=======
| <y> |
-------
Sesame (2.7.11) produces what you call the expected result (
?s = x
), so different from Jena and RDF::Query. I have not yet fully wrapped my head around the case to figure out who is right or wrong though.