SPARQL @ TPAC�
"2023-09-12"^^xsd:date
EXIST Issues
https://github.com/w3c/sparql-query/issues?q=is%3Aissue+is%3Aopen+exists
Some Examples
Location must be a variable:� EXISTS { BIND ( :e AS ?var ) ?s ?p ?z } , EXISTS { VALUES ?var (1 2 3) . . . }� EXISTS { SELECT ?var { . . . }� EXISTS { . . . BOUND(?var) . . . }��Variable scope� { ?s :p ?var } FILTER EXISTS { SELECT ?x { ?s :p ?var } }
Blank Nodes moved across BGPs
current row ?var = _:b123 FILTER EXISTS { ?var :p ?o } }
Related SPARQL Issues
Possible Solutions
Proposal A
This proposal for EXISTS emphasizes simplicity and the SPARQL notions of variable scoping and bottom-up evaluation of sub-queries over maximum compatibility with the current SPARQL definition for EXISTS. Its basic idea is to inject values for the variables in-scope just outside a FILTER expression at the beginning of the pattern argument to EXISTS almost as if a VALUES construct was injected there.
. . .
Change the definition of the exists function to:�Let μ be the current solution mapping for a filter, t a token, and P a graph pattern: The value exists(Initial(t),P) given D(G) is true iff eval(D(G),P') is a non-empty multiset of solution bindings, where P' is P with Initial(t) replaced by {μ}.
Summary�sparql-exists#proposal-a
SEP-0007 : Improved substitution
Intuition - SQL Correlated Subquery.
�The current row provides values for to use in the sub-query.
https://github.com/w3c/sparql-dev/blob/main/SEP/SEP-0007/sep-0007.md
Join ( { ?z = 53 } , � { :s :q ?o FILTER (?o < ?z ) }
)
?z = 53 :s :q ?o FILTER (?o < ?z )
Proposal-A: ?z not in scope at the filter
Correlated evaluation: ?z is in scope at the filter
PREFIX : <http://example/>
SELECT * { � BIND( 53 AS ?z )� EXISTS {
{ :s :q ?o FILTER ( ?z < ?o ) }
UNION
{ :s :r ?z }
}
}
EXISTS { Join( { ?z = 53 },� Union( :s :q ?o FILTER ( ?z > 26 ) ,� :s :r ?z� )� }
EXISTS { UNION(
{ ?z = 53 :s :q ?o FILTER ( ?z > 26 ) },
{ ?z = 53 :s :r ?z }
) }
Proposal-A: ?z not in scope at the filter
Correlated evaluation: ?z is in scope at the filter
Correlated Subquery Approach
How best to express injecting values:
There are only a few places where variables are associated with values.� BGPs, Paths , Assignment (BIND, VALUES, SELECT, GROUP BY) , GRAPH