What SPARQL command can be used to delete all graphs (except for Virtuoso system graphs) from a Virtuoso RDF store?

Can "DROP GRAPH <uri>" be combined with a subquery that selects URIs of all the graphs?

While there are some other ways to delete all triples in Virtuoso, they did not work correctly for me. SPARQL 1.1 defines "DROP [...] ALL" but looks like it is not implemented in Virtuoso yet.

asked 12 Nov '12, 13:22

captsolo.net's gravatar image

captsolo.net
1617
accept rate: 0%

(12 Nov '12, 15:39) Signified ♦ Signified's gravatar image
1

That question points to the other ways (Virtuoso-specific solutions, not SPARQL) to delete triples as described in http://www.openlinksw.com/dataspace/dav/wiki/Main/VirtRemoveTriples - (which did not quite work for me, more details if needed).

Plus that you can run "CLEAR GRAPH graph_URI" for each graph (but then it is multiple commands, one per each named graph).

What I am asking in this question is how to delete all graphs using SPARQL. E.g., if it is possible to write a single SPARUL statement that'd query for all graph URIs and execute DROP / CLEAR GRAPH on them.

(12 Nov '12, 17:14) captsolo.net captsolo.net's gravatar image

Temporarily solved this in a "procedural way" by querying for all graph URIs and then issuing CLEAR GRAPH for each one but that is a waste of resources when all this could be done server-side (if SPARQL provides a way to do this).

(12 Nov '12, 17:19) captsolo.net captsolo.net's gravatar image

You can't do exactly what you want as you can't input the results of a WHERE into a CLEAR or DROP command.

However you could do something like the following which should give you roughly the same effect:

DELETE
{
  ?s ?p ?o
}
WHERE
{
  # This clause finds graphs to delete
  GRAPH ?g
  {
    # Conditions used to identify graph(s) to delete go here
    # Avoid using ?s ?p and ?o here because they are used in the subsequent clause
  }
  # This clause finds all the triples from the graphs you wish to delete
  GRAPH ?g
  {
    ?s ?p ?o
  }
}

This isn't a great approach and the performance will likely be poor compared to using a CLEAR ALL or a DROP ALL because the engine has to select all the data in order to delete it.

If you simply want to delete the contents of all graphs you can simplify to the following:

DELETE WHERE { GRAPH ?g { ?s ?p ?o } }
link

answered 12 Nov '12, 19:18

Rob%20Vesse's gravatar image

Rob Vesse ♦
13.6k1715
accept rate: 29%

edited 12 Nov '12, 19:19

I'm a little confused as to why you don't want a Virtuoso-specific solution, when your question specified a Virtuoso back-end...

Questions specifically regarding Virtuoso are generally best raised on the public OpenLink Discussion Forums, the Virtuso Users mailing list, or through a confidential Support Case.

Virtuoso's SPARQL 1.1 implementation is still a work in progress. If you raise your need through the above paths, we should be able to notify you of progress and/or completion.

Depending on what you're using as a client tool, you could write a procedure that first queries for all graph names, and then steps through the list DROPping each. Similar could be done with Virtuoso's internal procedure language, and run through iSQL or any other SQL connection, using our SPASQL (or SPARQL-in-SQL) feature.

link

answered 14 Nov '12, 23:30

TallTed's gravatar image

TallTed
2.1k19
accept rate: 14%

Thanks for pointing to Virtuoso feedback channels. Will mention this question over there. Would be good to get SPARQL DROP ALL / CLEAR ALL in Virtuoso.

I tried some Virtuoso-specific solutions before posting this question (e.g. RDF_GLOBAL_RESET) but got into (a) permission problems running it from a user other than DBA; or (b) other problems if deleting all triples from RDF quads table (so it seems the system triples are there for a reason).

(19 Nov '12, 10:35) captsolo.net captsolo.net's gravatar image

I work with data sets around 100-500M triples regularly w/ Virtuoso.

Honestly I don't know how long it takes to CLEAR GRAPH when the graph is that big because I've never waited for it to finish.

I just shut the server down, delete all the virtuoso.* files other than virtuoso.ini, and restart the server.

In an unstriped setup it is back up in < 30 seconds. If you have stripes it may spend some time filling them before it starts but this is still much quicker than CLEAR GRAPH for a huge graph.

link

answered 17 Nov '12, 14:05

database_animal's gravatar image

database_animal ♦
8.3k612
accept rate: 15%

A good point. Makes sense for large datastore sizes.

My particular case is for testing the application so (1) there are just a few RDF triples and (2) emptying the store needs to be done programmatically. Hence easier to do via SPARQL and no need to worry about how long it takes.

(19 Nov '12, 10:39) captsolo.net captsolo.net's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×192
×55
×45

Asked: 12 Nov '12, 13:22

Seen: 1,195 times

Last updated: 19 Nov '12, 10:39