如何通过gremlinpython获取所有边、关联顶点以及相应的id、标签和属性?

2024-05-15 22:00:30 发布

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

我想从我的AWS Neptune DB获取所有边和关联的顶点。此外,我还需要节点和边缘的id、标签和属性。
我的数据是作为属性图存储的,我使用gremlin-python来查询它。在

下面是一个在gremlin shell中执行时提供所需数据的查询。但是,尝试使用gremlin python执行同样的操作会导致错误。在

g.V().bothE().otherV().limit(2).path().by(__.valueMap(true))

Python变体

^{pr2}$

错误

GremlinServerError: 498: {"requestId":"...","code":"UnsupportedOperationException","detailedMessage":"org.apache.tinkerpop.gremlin.process.traversal.step.util.ImmutablePath cannot be cast to org.apache.tinkerpop.gremlin.structure.Element"}

有人能给我一个获取所需信息的方法吗?不管是成功地将上述查询转换为Python,还是通过其他一些查询。在


Tags: 数据orgawsiddb属性节点apache
1条回答
网友
1楼 · 发布于 2024-05-15 22:00:30

你的遍历在我看来是有效的,事实上在TinkerGraph上运行得很好:

gremlin> g.V().bothE().otherV().limit(2).path().by(__.valueMap(true))
==>[[id:1,name:[marko],label:person,age:[29]],[id:9,weight:0.4,label:created],[id:3,name:[lop],lang:[java],label:software]]
==>[[id:1,name:[marko],label:person,age:[29]],[id:7,weight:0.5,label:knows],[id:2,name:[vadas],label:person,age:[27]]]

我希望这能奏效。也许那是海王星的一个虫子?请注意,使用select()可以得到相同的结果,但它有点冗长:

^{pr2}$

当然,您可以unfold()生成Map实例,以获得与path()相同的输出格式

gremlin> g.V().as('a').bothE().as('b').otherV().as('c').limit(2).select('a','b','c').by(valueMap(true)).map(unfold().select(values).fold())
==>[[id:1,name:[marko],label:person,age:[29]],[id:9,weight:0.4,label:created],[id:3,name:[lop],lang:[java],label:software]]
==>[[id:1,name:[marko],label:person,age:[29]],[id:7,weight:0.5,label:knows],[id:2,name:[vadas],label:person,age:[27]]]

相关问题 更多 >