本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
Amazon Neptune 會使用兩種不同格式,將圖形變更資料序列化至日誌串流,取決於是使用 Gremlin 還是 SPARQL 建立圖形。
這兩種格式共用通用的記錄序列化格式 (如 Neptune 串流 API 回應格式 中所述),其中包含下列欄位:
commitTimestamp
– 已請求遞交交易的時間,以毫秒為單位,從 Unix epoch 開始。eventId
– 串流變更記錄的序列識別符。data
– 序列化的 Gremlin、SPARQL 或 openCypher 變更記錄。以下幾節會詳細描述每筆記錄的序列化格式。op
– 已建立變更的操作。
PG_JSON 變更序列化格式
注意
從引擎 1.1.0.0 版開始,Gramlin 串流端點 (https://
) 輸出的 Gremlin 串流輸出格式 (Neptune-DNS
:8182/gremlin/streamGREMLIN_JSON
) 正被棄用。它被 PG_JSON 取代,目前與 GREMLIN_JSON
相同。
Gremlin 或 openCypher 變更記錄 (包含在日誌串流回應的 data
欄位中) 具有下列欄位:
-
id
– 字串 (必要)。Gremlin 或 openCypher 元素的 ID。
-
type
– 字串 (必要)。此 Gremlin 或 openCypher 元素的類型。必須是下列其中之一:
vl
- Gremlin 的頂點標籤;openCypher 的節點標籤。vp
- Gremlin 的頂點屬性;openCypher 的節點屬性。e
- Gremlin 的邊緣和邊緣標籤;OpenCypher 的關係和關係類型。ep
- Gremlin 的邊緣屬性;openCypher 的關係屬性。
-
key
– 字串 (必要)。屬性名稱 對於元素標籤,這是「標籤」。
-
value
–value
物件 (必要)。這是 JSON 物件,其中包含值本身的
value
欄位,以及該值之 JSON 資料類型的datatype
欄位。"value": { "value": "
the new value
", "dataType": "the JSON datatype of the new value
" } -
from
– 字串 (選用)。如果這是邊緣 (type="e"),則為對應「來源」頂點或來源節點的 ID。
-
to
– 字串 (選用)。如果這是邊緣 (type="e"),則為對應「目標」頂點或目標節點的 ID。
Gremlin 範例
-
以下是 Gremlin 頂點標籤的範例。
{ "id": "
an ID string
", "type": "vl", "key": "label", "value": { "value": "the new value of the vertex label
", "dataType": "String" } } -
以下是 Gremlin 頂點屬性的範例。
{ "id": "
an ID string
", "type": "vp", "key": "the property name
", "value": { "value": "the new value of the vertex property
", "dataType": "the datatype of the vertex property
" } } -
以下是 Gremlin 邊緣的範例。
{ "id": "
an ID string
", "type": "e", "key": "label", "value": { "value": "the new value of the edge
", "dataType": "String" }, "from": "the ID of the corresponding "from" vertex
", "to": "the ID of the corresponding "to" vertex
" }
openCypher 範例
-
以下是 openCypher 節點標籤的範例。
{ "id": "
an ID string
", "type": "vl", "key": "label", "value": { "value": "the new value of the node label
", "dataType": "String" } } -
以下是 openCypher 節點屬性的範例。
{ "id": "
an ID string
", "type": "vp", "key": "the property name
", "value": { "value": "the new value of the node property
", "dataType": "the datatype of the node property
" } } -
以下是 openCypher 關係的範例。
{ "id": "
an ID string
", "type": "e", "key": "label", "value": { "value": "the new value of the relationship
", "dataType": "String" }, "from": "the ID of the corresponding source node
", "to": "the ID of the corresponding target node
" }
SPARQL NQUADS 變更序列化格式
Neptune 會使用 W3C RDF 1.1 N-QuadsN-QUADS
語言,將變更記錄到圖形中的 SPARQL 四元組。
變更記錄中的 data
欄位只包含 stmt
欄位,其中保留 N-QUADS 陳述式,表示已變更的 quad,如下列範例所示。
"stmt" : "<https://test.com/s> <https://test.com/p> <https://test.com/o> .\n"