How to select optional graph structures with Gremlin?

前端 未结 1 1561
日久生厌
日久生厌 2021-01-06 21:55

I am using Gremlin to query a graph stored in TitanDB.

The graph contains user vertices with properties, e.g., \"description\", and edges denoting relationships betw

相关标签:
1条回答
  • 2021-01-06 22:36

    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:[]]
    
    0 讨论(0)
提交回复
热议问题