小精灵 - 无法添加边缘属性



我在使用 gremlin_python 包装器向边缘添加属性时遇到很大问题。

我能够创建边缘,如下所示:

eid1='123'
eid2='456'
edge = g.V().has('eid', eid1).addE('transaction').to(g.V().has('entity_id',eid2)).next()

但是,向边缘添加属性不起作用。如:代码运行没有错误,但边缘本身没有发生任何更改,所以当我调用 g.E(edge).valueMap.toList() 后,它会返回一个空列表。

g.E(edge).property('foo','bar').iterate()    <-- I've also tried this without iterate.

如果我创建节点并在同一行代码上添加属性,它也不起作用。

相同的代码 - 但在 gremlin 控制台中执行 - 按预期运行。 即,在创建边缘并分配属性后:

gremlin> g.E(edge).valueMap().toList()
==>{foo=bar}

这里的任何帮助将不胜感激。


更新

我无法使用图形遍历对象上的python包装器使其工作,而是通过客户端运行代码,该客户端按预期工作。但这是一种解决方法,而不是解决方案。

gremlin_client = client.Client('ws://localhost:8182/gremlin', 'g')
query = "g.V().has('eid', '123').addE('transaction').to(g.V().has('eid','456')).property('foo','bar').next()"
gremlin_client.submit(query).all().result()

我在 3.4.3-SNAPSHOT 上测试了您的方案,没有看到问题:

>>> g.addV().property('entity_id','123').iterate()
[['addV'], ['property', 'entity_id', '123'], ['none']]
>>> g.addV().property('entity_id','456').iterate()
[['addV'], ['property', 'entity_id', '456'], ['none']]
>>> e = g.V().has('entity_id','123').addE('transaction').to(__.V().has('entity_id','456')).next()
>>> g.E(e).property('foo','bar').iterate()
[['E', e[4][0-transaction->2]], ['property', 'foo', 'bar'], ['none']]
>>> g.E(e).valueMap().toList()
[{u'foo': u'bar'}]

我确实注意到您的示例代码确实存在语法错误 - 查看:

eid1='123'
eid2='456'
edge = g.V().has('eid', eid1).addE('transaction').to(g.V().has('entity_id',eid2)).next()

具体来说,您将"eid"和"entity_id"混合为顶点标识符。假设"eid"是错误的,它应该是"entity_id",我可以看到这个遍历如何在没有更新的情况下失败(因为从未找到初始顶点(,然后让你处于无法更新边缘的位置,因为它从未创建过。

为了回应下面的评论,我也尝试了这个,包括一个property()更新 TinkerGraph,没有遇到问题:

>>> g.addV().property('entity_id','123').iterate()
[['addV'], ['property', 'entity_id', '123'], ['none']]
>>> g.V().toList()
[v[0]]
>>> g.addV().property('entity_id','456').iterate()
[['addV'], ['property', 'entity_id', '456'], ['none']]
>>> g.V().has('entity_id','123').addE('transaction').to(__.V().has('entity_id','456')).property('weight',0.1).property('time',1000000).iterate()
[['V'], ['has', 'entity_id', '123'], ['addE', 'transaction'], ['to', [['V'], ['has', 'entity_id', '456']]], ['property', 'weight', 0.1], ['property', 'time', 1000000], ['none']]
>>> g.E().valueMap().toList()
[{'time': 1000000, 'weight': 0.1}]

我真的不确定可能出了什么问题。

我陷入了同样的情况。使用edgeid.id['@value']['relationId']对我有用。

g.E(edgeid.id['@value']['relationId']).property('foo','bar').iterate()

当我们简单地在 gremlin python 中使用 g.E() 时,它可以工作,但以我们期望的方式不支持使用 edge 来过滤边缘。 g.E(edge).toList()是空的。我认为它无法搜索边缘。所以我直接使用relationId,它奏效了。

最新更新