I have tree data structure in graph as shown in below diagram. Each color represents node with different labels with relation like employee -> app -> project -> pv -> scan).
Question #1:
I want to find all leaf nodes (ones in green) of top node 0.
I tried below code with loop which returns all nodes with label employee. Not just leaf nodes.
g.V().has('person', 'id', '0').repeat(__.in('reportsTo')).emit().values('id')
Sample graph can be found in gremlinbin.
How do I find all green leaf nodes?
Update #1:
As mentioned in comments, I tried tree pattern. But it doesn't let me call getLeafObjects() on tree. Not sure what's missing. Also, again I am able to create tree of employee nodes only. How to traverse to scan nodes?
> tree = g.V().has('person', 'id', '0').repeat(__.in('reportsTo')).emit().tree()
> tree.getLeafObjects()
No signature of method: org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal.getLeafObjects() is applicable for argument types: () values: []
Question #2:
How do I retrieve a child vertex amongst children under each parent based on max(id)? So in my sample graph, each black vertex can have one or more green child vertex. I want to find the green vertices with max(property) under each black vertices.