[Mulgara-general] SPARQL query against the union of all graphs

Paul Gearon gearon at ieee.org
Wed Nov 2 13:46:26 UTC 2011


Hi,

Sorry for the slow response. I've been down with a virus.

On Sun, Oct 30, 2011 at 11:15 PM, Doug Whitehead
<doug.whitehead at gmail.com> wrote:
> I've used Virtuoso and Sesame, and the default graph in Mulgara seems
> different.
> Is there some way to write a query to be against the union of all graphs?

Yes, it's different. The default graph isn't defined to be anything in
particular, and from memory Virtuoso returns the union of all graphs.
That's fine, but it means that you can't update the default graph,
doesn't it?

Anyway, Mulgara uses a particular named graph, and the graph that it
uses can be set in the configuration.

> I have seen in the mailing list earlier this year that one can do something
> like:
>
> SELECT ... WHERE { GRAPH ?g { .... } }

This will work for a general SPARQL engine, so long as you don't have
any FROM NAMED clauses, or a named-graph-uri parameter set in the
protocol. I can't recall if setting a FROM will affect it. (I think it
does, but I need to check)

> and the above seems to work fine for simple queries. But if the query is
> complicated and is to be fulfilled by data from multiple graphs, I don't
> think this works properly.

Can you provide an example where it doesn't work? As I already
mentioned, setting the graphs that you're selecting from will change
the list of graphs that will get bound to the ?g variable.

> More specifically, I think the above will return
> results where all matching data is found in the same graph.

Yes, if you have a pair of patterns that may appear in different
graphs, then you need to specify them for different graphs. e.g.

SELECT *
WHERE {
  GRAPH ?g1 { ?person rdf:type foaf:Person } .
  GRAPH ?g2 { ?person foaf:firstName "Fred" }
}

This works regardless of which graphs the data is in. If you wrapped
it all in a single GRAPH statement, then it would require all of the
data to be in a single graph, though it wouldn't matter which graph
that was.

This is actually more about SPARQL than Mulgara in particular. If you
really need to make a query against all the graphs, and assume that
you find the SPARQL approach to be cumbersome, then you could create a
view in Mulgara that includes all of the graphs, and select from the
view. The main problem with that is that it needs you to specify all
the graphs in the view, and doesn't just include all graphs
automatically.

Regards,
Paul


More information about the Mulgara-general mailing list