How to select optional graph structures with Gremlin?

天大地大妈咪最大 提交于 2019-12-01 00:57:10

You could do:

g.V('description',CONTAINS,'developer').as('user').transform{it.bothE.toList()}.as('relationship').select

in this way, you should get an empty list for those developers who don't have edges.

In TinkerPop 3.x, using the TinkerPop modern graph where I dropped edge with id 12, you would do:

gremlin> g.E(12).drop()
gremlin> g.V().hasLabel('person').as('u').
......1>       map(bothE().fold()).as('r').
......2>       select('u','r')
==>[u:v[1],r:[e[9][1-created->3],e[7][1-knows->2],e[8][1-knows->4]]]
==>[u:v[2],r:[e[7][1-knows->2]]]
==>[u:v[4],r:[e[10][4-created->5],e[11][4-created->3],e[8][1-knows->4]]]
==>[u:v[6],r:[]]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!