1

我在使用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()
4

2 回答 2

1

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

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

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

于 2021-07-22T08:50:28.190 回答
1

我在 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}]

我真的不确定有什么问题。

于 2019-06-20T14:36:48.393 回答