【问题标题】:Can't add vertex with python in neptune workbench无法在海王星工作台中使用 python 添加顶点
【发布时间】:2020-05-28 15:18:05
【问题描述】:

我正在尝试使用 Neptune 工作台制作 Neptune 的演示,但有些东西无法正常工作。我已经设置了这个块:

from __future__  import print_function  # Python 2/3 compatibility

from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection

graph = Graph()

cluster_url = #my cluster

remoteConn = DriverRemoteConnection( f'wss://{cluster_url}:8182/gremlin','g')

g = graph.traversal().withRemote(remoteConn)


import uuid

tmp = uuid.uuid4()
tmp_id=str(id)

def get_id(name):
    uid = uuid.uuid5(uuid.NAMESPACE_DNS, f"{name}.licensing.company.com")
    return str(uid)


def add_sku(name):
    tmp_id = get_id(name)
    g.addV('SKU').property('id', tmp_id, 'name', name)
    return name

def get_values():
    return g.V().properties().toList()


问题是调用add_sku 不会导致将顶点添加到图形中。在具有 gremlin 魔法的单元格中执行相同的操作,我可以通过 python 检索值,但我不能添加顶点。有人看到我在这里缺少什么吗?

【问题讨论】:

    标签: amazon-neptune gremlinpython


    【解决方案1】:

    Python 代码不起作用,因为它在其末尾缺少 terminal 步骤(next() 或 iterate()),这迫使它进行评估。如果您添加终端步骤,它应该可以工作:

    g.addV('SKU').property('id', tmp_id, 'name', name).next()
    

    【讨论】:

    • 对于登陆这个的人,我使用.iterate()而不是.next()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多