Using SPARQL UPDATE UNLOAD to delete data from Neptune - Amazon Neptune
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Using SPARQL UPDATE UNLOAD to delete data from Neptune

Neptune also provides a custom SPARQL operation, UNLOAD, for removing data that is specified in a remote source. UNLOAD can be regarded as a counterpart to the LOAD operation. Its syntax is:

Note

This feature is available starting in Neptune engine release 1.0.4.1.

UNLOAD SILENT (URL of the remote data to be unloaded) FROM GRAPH (named graph from which to remove the data)
  • SILENT   –   (Optional) Causes the operation to return success even if there was an error when processing the data.

    This can be useful when a single transaction contains multiple statements like "LOAD ...; LOAD ...; UNLOAD ...; LOAD ...;" and you want the transaction to complete even if some of the remote data could not be processed.

  • URL of the remote data to be unloaded   –   (Required) Specifies a remote data file containing data to be unloaded from a graph.

    The remote file must have one of the following extensions (these are the same formats that UPDATE-LOAD supports):

    • .nt for NTriples.

    • .nq for NQuads.

    • .trig for Trig.

    • .rdf for RDF/XML.

    • .ttl for Turtle.

    • .n3 for N3.

    • .jsonld for JSON-LD.

    All the data that this file contains will be removed from your DB cluster by the UNLOAD operation.

    Any Amazon S3 authentication must be included in the URL for the data to unload. You can pre-sign an Amazon S3 file and then use the resulting URL to access it securely. For example:

    aws s3 presign --expires-in (number of seconds) s3://(bucket name)/(path to file of data to unload)

    Then:

    curl https://(a Neptune endpoint URL):8182/sparql \ --data-urlencode 'update=unload (pre-signed URL of the remote Amazon S3 data to be unloaded) \ from graph (named graph)'

    For more information, see Authenticating Requests: Using Query Parameters.

  • FROM GRAPH (named graph from which to remove the data)   –   (Optional) Specifies the named graph from which the remote data should be unloaded.

    Neptune associates every triple with a named graph. You can specify the default named graph using the fallback named-graph URI, http://aws.amazon.com/neptune/vocab/v01/DefaultNamedGraph, like this:

    FROM GRAPH <http://aws.amazon.com/neptune/vocab/v01/DefaultNamedGraph>

In the same way that LOAD corresponds to INSERT DATA { (inline data) }, UNLOAD corresponds to DELETE DATA { (inline data) }. Like DELETE DATA, UNLOAD does not work on data that contains blank nodes.

For example, if a local web server serves a file named data.nt that contains the following 2 triples:

<http://example.org/resource#a> <http://example.org/resource#p> <http://example.org/resource#b> . <http://example.org/resource#a> <http://example.org/resource#p> <http://example.org/resource#c> .

The following UNLOAD command would delete those two triples from the named graph, <http://example.org/graph1>:

UNLOAD <http://localhost:80/data.nt> FROM GRAPH <http://example.org/graph1>

This would have the same effect as using the following DELETE DATA command:

DELETE DATA { GRAPH <http://example.org/graph1> { <http://example.org/resource#a> <http://example.org/resource#p> <http://example.org/resource#b> . <http://example.org/resource#a> <http://example.org/resource#p> <http://example.org/resource#c> . } }
Exceptions thrown by the UNLOAD command
  • InvalidParameterException   –   There were blank nodes in the data. HTTP status: 400 Bad Request.

    Message: Blank nodes are not allowed for UNLOAD

     

  • InvalidParameterException   –   There was broken syntax in the data. HTTP status: 400 Bad Request.

    Message: Invalid syntax in the specified file.

     

  • UnloadUrlAccessDeniedException   –   Access was denied. HTTP status: 400 Bad Request.

    Message: Update failure: Endpoint (Neptune endpoint) reported access denied error. Please verify access.

     

  • BadRequestException   –   The remote data cannot be retrieved. HTTP status: 400 Bad Request.

    Message: (depends on the HTTP response).