gremlin-python-无法添加边缘属性

时间:2019-06-19 15:04:59

标签: python gremlin tinkerpop tinkerpop3 gremlin-server

使用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> g.E(edge).valueMap().toList()
==>{foo=bar}

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

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

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()

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


更新

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

search

2 个答案:

答案 0 :(得分:1)

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

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

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

答案 1 :(得分:0)

我在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”,我可以看到这种遍历在没有更新的情况下将失败(因为从未找到初始顶点),然后使您处于无法更新边缘的位置,因为它是从未创造。

相关问题