使用 Python 的 gremlin 模块将顶点添加到 Amazon Neptune 图形数据库

Use gremlin module for Python to add vertex to Amazon Neptune graph database

剧情简介

我正在尝试在 Amazon EC2 实例上使用 Python,在与 Amazon Neptune 实例相同的 VPC 中,向 Neptune 添加顶点(节点)。使用 example code for Amazon Neptune,我构建了以下代码示例以添加一个顶点(节点),然后打印出图中的 所有 个顶点。

from gremlin_python import statics
from gremlin_python.process.anonymous_traversal import traversal
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.structure.graph import Graph

from pprint import pprint


target = 'zzzzzz-instance-1.zzzzzzzz.us-west-2.neptune.amazonaws.com'
port = '8182'

g = Graph()

remote = DriverRemoteConnection(f'wss://{target}:{port}/gremlin', 'g')
conn = g.traversal().withRemote(remote)
conn.addV('person').property(id, 5).property('firstname', 'Trevor')
print(conn.V().toList())

实际行为

conn.addV() 的调用无声地失败,并且带有 print() 语句的下一行 returns 是一个空的 Python 列表。

预期行为

  1. conn.addV()的调用抛出异常,或者...
  2. 调用conn.addV()成功,print()行returns顶点

问题:如何在 Amazon Neptune 中使用 Python 的 Gremlin 模块向图中添加顶点?

您的 addV() 查询需要终止步骤,例如 next() 或 iterate()。否则,您将获得返回的查询的字节码表示。 http://www.kelvinlawrence.net/book/PracticalGremlin.html#var