-
Notifications
You must be signed in to change notification settings - Fork 543
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
Serializing SPARQL Query Results with Aggregates over Variables from Optional Graph Pattern #2229
Comments
I couldnt generate that error(with python 3.11). My script:
|
Hi @WhiteGobo, this is because all of your instances (<1>, <2>, and <3>) have a connection to at least ex:b or ex:c via ex:d. If you remove the last triple, expecting the count for <3> to be 0 (zero), then the same error appears. import rdflib
query = """
SELECT DISTINCT ?x (COUNT(DISTINCT ?inst) as ?cnt)
WHERE {
?x a ex:a
OPTIONAL {
VALUES ?inst {ex:b ex:c}.
?x ex:d ?inst.
}
} GROUP BY ?x
"""
ex = rdflib.Namespace("http://example.com/")
g = rdflib.Graph()
g.bind("ex", ex)
g.parse(format="ttl", data="""@prefix ex: <http://example.com/>.
<1> a ex:a;
ex:d ex:b.
<2> a ex:a;
ex:d ex:c;
ex:d ex:b.
<3> a ex:a.
""")
print(list(g.query(query))) |
Ok i have made a fix in an extra branch. That should resolve that Error. I need some time to make a PR out of this, because i would create a test and ive got to look at |
testing counting of optional nodes. Zero optional nodes may throw a NotBoundError Added fix for NotBoundError, for this test.
testing counting of optional nodes. Zero optional nodes may throw a NotBoundError Added fix for NotBoundError, for this test.
I ran into an issue when serializing the results of SPARQL queries with aggregates from optional graph patterns, i.e., they might potentially be unbound. I am using
rdflib==6.2.0
.The query in question is:
For each graduate student, I want to know how many undergraduate degrees he/she has from the list of universities provided using the VALUES clause. I am using OPTIONAL here since I am also interested in getting
0
if the student doesn't have a degree from one of the specified universities.The query runs fine in my SPARQL endpoint but when I try to use rdflib as an in-memory RDF graph, I get the following exception:
I tried the following rewriting of my original query to bypass that issue but with no success.
To my understanding, the error should occur in the count which shouldn't be executed due to the IF statement.
Many thanks in advance!
The text was updated successfully, but these errors were encountered: