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
- I didn't change the behavior of triples duplicated in different named graphs when those named graphs are merged into the query's default graph. Would need further discussion
- I didn't change the behavior or the updates (
DELETE
andINSERT
). Since code is independent, I will probably make another PR for that
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
- Checked that there aren't other open pull requests for
the same change. - Checked that all tests passes .
- [] type checking: black and flake8 do not agree on how to format some lines, I chose to take black's suggestions
- If the change has a potential impact on users of this project:
- Added or updated tests that fail without the change.
- Updated relevant documentation to avoid inaccuracies. Just following W3C spec, which link is already in the docs.
- Considered adding additional documentation.
- Considered granting push permissions to the PR branch,
so maintainers can fix minor issues and keep your PR up to date.