Fri 29 Dec 2006

Unrolling nested queries

This afternoon I was pondering additional SPARQL verbs, such as REPLACE and INSERT. It just occurred to me that nested queries can be partially ‘unrolled’ by something like INSERT*. Here's how it could work.

You have a nested query: that is, you have a query fragment that returns results to be used as the data source for another query fragment. As SPARQL doesn't implement this, I leave it to your imagination as to whether this is a kind of iterative generation of bindings, or building an intermediate graph; the two are readily interchangeable.

This is similar to a common feature of programming languages; in Javascript (for a convenient notation), querying would be defined and used like this:
  function query(query, data) { ... }
result = query("SOME QUERY", query("INNER QUERY", db));
Phrased this way, one can easily state the nesting problem and its solution: you can't nest function calls, so let's make an intermediate variable.
  intermediate = query("INNER QUERY", db);
result = query("SOME QUERY", intermediate);
In SPARQL terms, a nested query like
  SELECT * FROM { 
CONSTRUCT { ... }
WHERE { ... }
}
WHERE { ... }
can be unrolled into two consecutive queries:
  INSERT INTO <somegraph>
{ ... }
WHERE { ... }
  SELECT * FROM NAMED <somegraph>
WHERE { ... }
This presupposes the existence of INSERT, which is just like CONSTRUCT but saves its output into a new graph. I don't think this is a big stretch; something like INSERT is arguably very necessary in real-world systems (though it can be finessed by additional parameters in the environment of a CONSTRUCT query).

This also leaves the intermediate graph in the store, perhaps to be discarded later (or perhaps to be reused). I can see that being a problem.

* perhaps better called ASSERT, eh?


Posted at 2006-12-29 19:13:04 by RichardLink to Unrolling nested q…
Comments, trackbacks.

I can't believe I'm at work today

There are about 20 people at work, total, and most of them are drinking Bloody Marys. That's the end of December, I suppose!

Posted at 2006-12-29 12:43:36 by RichardLink to I can't believe I'…
Comments, trackbacks.

Google
Web holygoat.co.uk
  • richard is: