Neptune Streams 中的序列化格式 - Amazon Neptune

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Neptune Streams 中的序列化格式

Amazon Neptune 使用两种不同的格式来将图形更改数据序列化到日志流,具体取决于该图形是使用 Gremlin 还是 SPARQL 创建的。

这两种格式共享一种通用的记录序列化格式,如Neptune Streams API 响应格式中所述,该格式包含以下字段:

  • commitTimestamp – 请求提交事务的时间(使用 Unix 纪元时间表示,单位为毫秒)。

  • eventId – 流更改记录的序列标识符。

  • data— 序列化的 Gremlin、SPARQL 或变更记录。 OpenCypher 下面的各部分中更详细地介绍了每个记录的序列化格式。

  • op – 造成更改的操作。

PG_JSON 更改序列化格式

注意

引擎版本 1.1.0.0 开始,Gremlin 流端点 (https://Neptune-DNS:8182/gremlin/stream) 输出的 Gremlin 流输出格式 (GREMLIN_JSON) 已被弃用。它被 PG_JSON 取代,PG_JSON 当前与 GREMLIN_JSON 相同。

日志流响应的 data 字段中包含的 Gremlin 或 openCypher 更改记录具有以下字段:

  • id – 字符串,必需。

    Gremlin 或 openCypher 元素的 ID。

  • type – 字符串,必需。

    Gremlin 或 openCypher 元素的类型。必须是以下类型之一:

    • vl – Gremlin 的顶点标签;openCypher 的节点标签。

    • vp – Gremlin 的顶点属性;openCypher 的节点属性。

    • e – Gremlin 的边缘和边缘标签;openCypher 的关系和关系类型。

    • ep – Gremlin 的边缘属性;openCypher 的关系属性。

  • key – 字符串,必需。

    属性名称。对于元素标签,此为“label”。

  • valuevalue 对象,必需。

    这是一个 JSON 对象,其中包含 value 字段(存储值本身)和 datatype 字段(存储该值的 JSON 数据类型)。

    "value": { "value": "the new value", "dataType": "the JSON datatype of the new value" }
  • from – 字符串,可选。

    如果这是一个边缘(类型 = e),则为相应的 from 顶点或源节点的 ID。

  • to – 字符串,可选。

    如果这是一个边缘(类型 = e),则为相应的 to 顶点或目标节点的 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-Quads 规范中定义的资源描述框架 (RDF) N-QUADS 语言在图形中记录对 SPARQL 四元组的更改。

更改记录中的 data 字段仅包含一个 stmt 字段,该字段包含表示更改后的四元组的 N-QUADS 语句,如以下示例所示。

"stmt" : "<https://test.com/s> <https://test.com/p> <https://test.com/o> .\n"