无法在 gremlin 中创建边缘

问题描述 投票:0回答:1

我尝试运行下面的查询:

edge = g.V(id).addE("rated").to(g.V(n_id)).next()

但我收到错误

InvalidRequest: Error from server: code=2200 [Invalid query] message="Could not read the traversal from the request sent. Error was: Could not locate method: DefaultGraphTraversal.addE([rated, [GraphStep(vertex,[{source_id=34897306, source_system=MSI_CLIENT, ~label=person}])]])"

g.V(id)
g.V(n_id)
都返回顶点,我没有看到任何问题。有人可以告诉我为什么我会遇到上述错误吗?

gremlin graph-databases datastax gremlinpython dse
1个回答
0
投票

gremlinpython 有一个怪癖,它阻止您以这种方式将遍历嵌套在其他遍历中。当您在遍历中嵌套

V()
时,必须使用
__
类,如下所示:
__.V()
。您可以将
__
类导入为
from gremlin_python.process.graph_traversal import __

下面的代码应该可以工作:

from gremlin_python.process.anonymous_traversal import traversal
from gremlin_python.process.graph_traversal import __, GraphTraversalSource
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection

g: GraphTraversalSource = traversal().withRemote(
    DriverRemoteConnection(GRAPH_DB_URL, 'g',
                           username=GRAPH_DB_USER,
                           password=GRAPH_DB_PASSWORD)
)

edge = g.V(id).addE("rated").to(__.V(n_id)).next()
© www.soinside.com 2019 - 2024. All rights reserved.