gremlinpython无法添加边缘属性

2024-06-28 20:55:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用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()之后,它返回一个空列表。在

^{pr2}$

如果我在同一行代码上创建节点并添加属性,也无法正常工作。在

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

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

Tags: to代码client属性边缘nexttransactionhas
1条回答
网友
1楼 · 发布于 2024-06-28 20:55:01

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

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

^{pr2}$

具体来说,您可以混合使用“eid”和“entity_id”作为顶点标识符。假设“eid”是错误的,它应该是“entity_id”,我可以看到如果没有更新,这个遍历会失败(因为没有找到初始顶点),然后让你处于一个无法更新边的位置,因为它从未被创建过。在

针对下面的评论,我也尝试了使用TinkerGraph进行property()更新,但没有遇到问题:

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

我真的不知道会出什么问题。在

相关问题 更多 >