how to return subgraph from gremlin that is in an easily consumable format for Java

前端 未结 1 429
無奈伤痛
無奈伤痛 2020-12-22 10:51

I am very frustrated about very simple things when I try to do a single traversal and bring a lot of stuff from DSE Graph 5.0 at once using Gremlin..

In my simplifie

相关标签:
1条回答
  • 2020-12-22 11:32

    If Entity:Type is a 1:n relationship, then you won't even need optional().

    g.V().has("Entity","uuid","6708ec6d-4518-4159-9005-9e9d642f157e").
      project("entity","types").by().by(outE("IsOfType").fold())
    

    The result will be of type List<Map<String, Object>>.

    UPDATE

    Following the short toList() discussion in the comments below, this is how you can work with a traversal result without storing the whole thing in a collection:

    g.V().has("Entity","uuid","6708ec6d-4518-4159-9005-9e9d642f157e")
            .project("entity","types").by().by(outE("IsOfType").fold())
            .forEachRemaining(m -> {
                final Vertex entityV = (Vertex) m.get("entity");
                final List<Edge> typeE = (List<Edge>) m.get("types");
                // whatever ...
            })
    
    0 讨论(0)
提交回复
热议问题