【问题标题】:Use gremlin module for Python to add vertex to Amazon Neptune graph database使用 Python 的 gremlin 模块将顶点添加到 Amazon Neptune 图形数据库
【发布时间】:2021-05-03 22:45:27
【问题描述】:

概要

我正在尝试在与 Amazon Neptune 实例位于同一 VPC 中的 Amazon EC2 实例上使用 Python 向 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() 语句的以下行返回一个空的 Python 列表。

预期行为

  1. conn.addV() 的调用会引发异常,或者...
  2. conn.addV() 调用成功,print() 行返回顶点

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

【问题讨论】:

    标签: python amazon-web-services tinkerpop amazon-neptune


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多