3

Sparql has a notion of a "default graph" that is queried when no graph context is specified, and which (depending on the triple store) may be the union of proper graphs available in a repository, or it may be a separate, "null graph"; so far so good.

But sparql also has a keyword DEFAULT that can be specified instead of a graph name, as in

SELECT *
FROM DEFAULT
WHERE { ... }

What does this command do? I can only interpret it as an explicit way to request the same thing that would happen when there's no FROM clause at all. But is this correct? I could find no documentation about it. And what about using it in update queries, or with CLEAR, COPY, etc.? Can anyone point to documentation of the meaning and intended use of this keyword, or at least shed some light on why it exists?

alexis
  • 48,685
  • 16
  • 101
  • 161

2 Answers2

3

FROM DEFAULT is a feature that has been proposed for future work sparql-1.2/issues/43.

The grammar covers both SPARQL Query and SPARQL Update because they share a considerable about of the grammar. They have different entry points (QueryUnit and UpdateUnit).

The DEFAULT keyword appears in GraphOrDefault and GraphRefAll. Both of which are only used in SPARQL Update.

ADD, MOVE, CODE use GraphOrDefault; CLEAR and DROP use GraphRefAll.

FROM is followed by either an iri, or NAMED iri.

Omitting FROM means the implicit default graph.

AndyS
  • 16,345
  • 17
  • 21
  • Thanks! This covers the syntax, but what do these commands do? With the information from @stanislav, it seems that DEFAULT refers to the null graph _instead_ of the "implicit default graph" (which is typically the union of all graphs). Is this correct? Does it apply to the UPDATE syntax as well as the SELECT proposal? – alexis May 10 '21 at 11:39
  • 1
    In SPARQL Update, it refers to the unnamed graph of the storage GraphStore. It is already in SPARQL Update 1.1. https://www.w3.org/TR/sparql11-update/ in SPARQLquery and update are different languages that use many of the same syntax elements. `COPY TO DEFAULT` copies all the triples in teh graph named to the default graph of the graph store. – AndyS May 10 '21 at 14:16
  • Thanks, I have studied the sparql11-update document and it is not explicit about what graph is affected when we write DEFAULT. (_Maybe_ it can be inferred from the other sections...) So what you write in your comment is new information. – alexis May 10 '21 at 14:27
  • Section2: "a Graph Store contains one (unnamed) slot holding a default graph and zero or more named slots holding named graphs." Its' "graph store" because its mutable - RDF graphs and RDF Dataset are immutable. So the execution model has to be "take old value, calculate new value, replace slot." – AndyS May 10 '21 at 18:17
2

When you have one or more FROM or FROM NAMED statements in a query then the dataset for the query is composed of only those graphs. Per SPARQL 1.1 Query Specification Section 13.2:

The FROM and FROM NAMED keywords allow a query to specify an RDF dataset by reference; they indicate that the dataset should include graphs that are obtained from representations of the resources identified by the given IRIs (i.e. the absolute form of the given IRI references). The dataset resulting from a number of FROM and FROM NAMED clauses is:

  • a default graph consisting of the RDF merge of the graphs referred to in the FROM clauses, and
  • a set of (IRI, graph) pairs, one from each FROM NAMED clause.

If there is no FROM clause, but there is one or more FROM NAMED clauses, then the dataset includes an empty graph for the default graph.

So basically the presence of those clauses creates a query dataset that potentially hides some/all graphs in the underlying dataset. Your query operates over this query dataset.

As noted in Andy's answer FROM DEFAULT is a proposed future extension to the SPARQL language that would allow explicitly referring to the datasets default graph (whatever that may be). Currently there's no standardised way to do this, so only queries that omit any FROM clauses can access the default graph unless your service provides some non-standard way to refer to it e.g. a custom URI for referencing the default graph.

For your specific example query:

SELECT *
FROM DEFAULT
WHERE { ... }

This would have the effect of forming a query dataset with a default graph using the services default and no named graphs visible i.e. any GRAPH ?g { } clauses would not match in this query

RobV
  • 28,022
  • 11
  • 77
  • 119