使用 SPARQL UPDATE UNLOAD 從 Neptune 刪除資料 - Amazon Neptune

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 SPARQL UPDATE UNLOAD 從 Neptune 刪除資料

Neptune 也提供自訂 SPARQL 操作 (UNLOAD),用於移除遠端來源中指定的資料。UNLOAD 可被視為 LOAD 操作的對應項。它的語法是:

注意

此功能從 Neptune 引擎 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 – (選用) 即使在處理資料時發生錯誤,也會導致操作傳回成功。

    這在單一交易包含多個陳述式 (例如,"LOAD ...; LOAD ...; UNLOAD ...; LOAD ...;") 時很有用,而且即使某些遠端資料無法處理,您也想要交易完成。

  • 要卸載的遠端資料 URL – (必要) 指定一個遠端資料檔案,其中包含要從圖形卸載的資料。

    遠端檔案必須具有下列其中一個副檔名 (這些是 UPDATE-LOAD 支援的相同格式):

    • NTriples 為 .nt

    • NQuads 為 .nq

    • Trig 為 .trig

    • RDF/XML 為 .rdf

    • Turtle 為 .ttl

    • N3 為 .n3

    • JSON-LD 為 .jsonld

    UNLOAD 操作將會從您的資料庫叢集中移除此檔案包含的所有資料。

    任何 Amazon S3 身分驗證都必須包含在 URL 中,才能卸載資料。您可以預先簽署 Amazon S3 檔案,然後使用產生的 URL 安全地存取該檔案。例如:

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

    然後:

    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)'

    如需詳細資訊,請參閱對請求進行身分驗證:使用查詢參數

  • FROM GRAPH (要從中移除資料的具名圖形) – (選用) 指定應從中卸載遠端資料的具名圖形。

    Neptune 會將每個三元組與一個具名圖形建立關聯。您可以使用後援具名圖形 URI 來指定預設的具名圖形 (http://aws.amazon.com/neptune/vocab/v01/DefaultNamedGraph),如下所示:

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

UNLOAD 會以 LOAD 對應至 INSERT DATA { (inline data) } 的相同方式對應至 DELETE DATA { (inline data) }。如同 DELETE DATAUNLOAD 無法對包含空白節點的資料運作。

例如,如果本機 Web 伺服器提供名為 data.nt 的檔案,其中包含以下兩個三元組:

<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> .

以下 UNLOAD 命令將從具名圖形 (<http://example.org/graph1>) 中刪除這兩個三元組:

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

這將與使用以下 DELETE DATA 命令具有相同的效果:

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> . } }
UNLOAD 命令擲回的例外狀況
  • InvalidParameterException – 資料中有空白節點。HTTP 狀態:400 錯誤的請求。

    訊息 Blank nodes are not allowed for UNLOAD

     

  • InvalidParameterException – 資料中有不完整的語法。HTTP 狀態:400 錯誤的請求。

    訊息Invalid syntax in the specified file.

     

  • UnloadUrlAccessDeniedException – 存取遭拒。HTTP 狀態:400 錯誤的請求。

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

     

  • BadRequestException – 無法擷取遠端資料。HTTP 狀態:400 錯誤的請求。

    訊息(取決於 HTTP 回應)。