Skip to content
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

SPARQLStore query parameter initBindings does not have the same behavior as the other stores #1772

Open
Tpt opened this issue Mar 23, 2022 · 1 comment
Labels
bug Something isn't working SPARQL store Related to a store.

Comments

@Tpt
Copy link
Contributor

Tpt commented Mar 23, 2022

RDFLib SPARQL query processor considers the initBindings parameter of the Store/Graph query method as a set of binds to do at the beginning of the query, inside of the SELECT expression. However SPARQLStore considers it as a join to be done after the query have been processed using a final VALUES clause when it generates a SPARQL query to send to the remote store.

For example the call

store.query("SELECT ?s WHERE { FILTER(BOUND(?s)) }", initBindings={Variable("s"): URIRef("http://example.com/foo")})

will be evaluated by the Memory store like

SELECT ?s WHERE { VALUES ?s { <http://example.com/foo> } FILTER(BOUND(?s)) }

and by the SPARQLStore like:

SELECT ?s WHERE { FILTER(BOUND(?s)) } VALUES ?s { <http://example.com/foo> }

This leads the Memory store to return one solution with the assignation ?s -> <http://example.com/foo> and the SPARQLStore to return no solution.

It would be great to harmonize the behavior. I encountered this issue while working on oxrdflib that currently follows the SPARQLStore behavior, breaking some usages relying on the Memory store behavior.

@ghost
Copy link

ghost commented Mar 26, 2022

I can confirm the issue. FWIW, I found what might be a workaround, you can set the use_store_provided kwarg to False and get the desired behaviour.
Using a Fuseki instance primed with:

INSERT DATA { 
    <http://example.org/book/book1>  <http://purl.org/dc/elements/1.1/title>  "SPARQL Tutorial" .
    <http://example.org/book/book1>  <http://example.org/ns#price>  42 .
    <http://example.org/book/book2>  <http://purl.org/dc/elements/1.1/title>  "The Semantic Web" .
    <http://example.org/book/book2>  <http://example.org/ns#price>  23 .
}

The following test passes:

from rdflib import Graph, Literal, URIRef, XSD
def test_bindings():
    g = Graph("SPARQLStore")
    g.open("http://localhost:3030/db/query")
    bindings = {Variable("book"): URIRef("http://example.org/book/book1")}
    query = "SELECT ?book WHERE { FILTER(BOUND(?book)) }"
    res = g.query(query, initBindings=bindings, use_store_provided=False)
    assert list(res) == [(rdflib.term.URIRef('http://example.org/book/book1'),)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SPARQL store Related to a store.
Projects
None yet
Development

No branches or pull requests

2 participants