-
Notifications
You must be signed in to change notification settings - Fork 555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bindings of variables are not carried into FILTERs in (NOT) EXISTS clauses #615
Comments
so you're complaining that the following query doesn't return any results:
This is actually by design in SPARQL: The inner-most query is evaluated first. The consequence is that we have the following execution order:
As the
Which correctly doesn't result in a binding for |
I don't think that this reasoning is correct. Look at Section 8.3.3 of SPARQL 1.1 Query Language, at The example there is
which is analogous to my example and the wording says that ?n is bound in the peter On 03/28/2016 03:39 AM, Jörn Hees wrote:
|
Is this a bug or is my understanding of SPARQL incorrect? |
To be honest, i'm not sure, which is why re-opened this... The link you point to seems to support your view-point, but jena seems to support mine: $ sparql -v --data=empty.n3 --query=<(echo '
> SELECT ?this WHERE {
> VALUES ?this { <y> <n> }
> FILTER (EXISTS {
> VALUES ?valu { <y> <o> }
> FILTER ( ?this = ?valu )
> })
> }
> ')
1 SELECT ?this
2 WHERE
3 { VALUES ?this { <y> <n> }
4 FILTER EXISTS { VALUES ?valu { <y> <o> }
5 FILTER ( ?this = ?valu )
6 }
7 }
13:39:05 INFO exec :: QUERY
SELECT ?this
WHERE
{ VALUES ?this { <y> <n> }
FILTER EXISTS { VALUES ?valu { <y> <o> }
FILTER ( ?this = ?valu )
}
}
13:39:05 INFO exec :: ALGEBRA
(project (?this)
(filter (exists
(table empty))
(table (vars ?this)
(row [?this <file:///dev/fd/y>])
(row [?this <file:///dev/fd/n>])
)))
--------
| this |
========
-------- That said, the SPARQL parsing and its conversion to an algebra isn't the easiest code and i just didn't find the time to look into this properly. |
I put together the example from the SPARQL 1.1 QL spec and it has the incorrect behaviour as well. [Again problems with uploading - I'll put it into a separate comment.] |
import rdflib
from rdflib import Namespace
from rdflib.term import Literal
from rdflib.namespace import XSD
EX = Namespace("http://example.com/")
g = rdflib.Graph()
g.add ( ( EX.a, EX.p, Literal(1,datatype=XSD.integer) ) )
g.add ( ( EX.a, EX.q, Literal(1,datatype=XSD.integer) ) )
g.add ( ( EX.a, EX.q, Literal(2,datatype=XSD.integer) ) )
g.add ( ( EX.b, EX.p, Literal(3.0,datatype=XSD.decimal) ) )
g.add ( ( EX.b, EX.q, Literal(4.0,datatype=XSD.decimal) ) )
g.add ( ( EX.b, EX.q, Literal(5.0,datatype=XSD.decimal) ) )
print "MINUS"
query = """PREFIX : <http://example.com/>
SELECT * WHERE {
?x :p ?n
MINUS {
?x :q ?m .
FILTER(?n = ?m)
}
}"""
result = g.query(query)
for row in result : print row
assert len(result) == 2
print "FILTER NOT EXISTS"
query = """PREFIX : <http://example.com/>
SELECT * WHERE {
?x :p ?n
FILTER NOT EXISTS {
?x :q ?m .
FILTER(?n = ?m)
}
}"""
result = g.query(query)
for row in result : print row
assert len(result) == 1 |
I believe this was broken by: 6200934 |
My understanding is that variable bindings carry into FILTER constructs. However, this sometime does not work in rdflib. I have a short example that shows this, with a FILTER inside a FILTER EXISTS. My belief is that the binding of ?this from the outermost portion should be visible in the innermost portion, meaning that the ?this = ?valu will only filter out solutions where the two variables have different bindings. However, all solutions appear to be filtered out, which would happen if the ?this binding(s) from the outermost portion are not making their way into the innermost portion.
This is very similar to the example in SPARQL 1.1 Query Language section 8.3.3.
bug2-rdflib.txt
The text was updated successfully, but these errors were encountered: