Fix explicit dataset (FROM and FROM NAMED clauses) by apicouSP · Pull Request #2794 · RDFLib/rdflib (original) (raw)

Summary of changes

WHAT

FROM or FROM NAMED clause: redefine entirely the query's RDF dataset

When a query (SELECT, CONSTRUCT, ASK, DESCRIBE) is using a FROM or FROM NAMED clause, we redefine entirely the query's RDF dataset
Include only the graphs in FROM clauses in the query's default graph
Include only the graphs in the FROM NAMED clauses in the query's named graphs

As a consequence, when a user defines a FROM clause in his query but does not define FROM NAMED, then the named graphs are considered empty set.
And vice versa: if a user defines a FROM NAMED clause but does not define a FROM clause, then the default graph is considered empty.
I added tests specifically for that
That's my interpretation of this

Also since the RDF Dataset is entirely redefined when using FROM or FROM NAMED clauses then for those queries the parameter SPARQL_DEFAULT_GRAPH_UNION will be ignored

Load external graphs only if they don't already exist

Try to load external graphs only if they don't already exist in the given ConjunctiveGraph

As a consequence, you don't have to set SPARQL_DEFAULT_GRAPH_UNION to False if all the graphs mentioned in FROM and FROM NAMED clauses already exist in the given ConjunctiveGraph

WHAT it is not

WHY:

So queries behave closer to W3C spec

Issues:

This PR fixes this issue (confirmed)
And also that issue as far as I understand
This also solves partially this discussion

Checklist