I am new to Gremlin struggling modify the query to get the appropriate result.
I have a query that gives the depth of the graph. The query is as below:
g.withSack(0)
.V('company_1')
.repeat(
outE('HAS_SHRHLDING_PC_TO')
.sack(sum).by(constant(1))
.inV()
.simplePath())
.until(not(outE()))
.sack()
.max()
.aggregate('x')
.fold()
.V(company_1)
.repeat(
outE('HAS_VOTING_PC_TO')
.sack(sum).by(constant(1))
.inV()
.simplePath())
.until(not(outE()))
.sack()
.max()
.aggregate('x')
.cap('x')
.unfold()
.max()
The output is return in number. The output is as below:
4
I am trying to modify this query to get the output as key-value pair, rather than only value as I have to add more one key and value to the output.
I want to retrieve the company_number that is passed in input along with the depth.
sample expected output:
{'company_number': 'company_1', 'depth': 4}
I tried to use project was unsuccessful in achieving the desired result. Any help would be appreciated. Thanks
Here's one way you might do it:
I avoid using
max()so that the path history isn't lost and we canselect('start')to get back to the start vertex. At that point, it's easy toproject()and then order by the "depth" to get the deepest one.To take this a step further, if you supplied multiple start vertices you would find that the query is grabbing the deepest point only. In other words, the
order().limit()is doing that globally for all start vertices which is great if you just want the deepest path. If you want the deepest path per start vertex you need to usemap():