2

We use Gremlin 3.2 compatible database. Actually, we try Cosmos DB in graph/gremlin mode. But I am looking to gremlin query so not necessary it is related only to Cosmos DB

The graph looks like on the image below enter image description here

I have created a query that is able to capture red vertices/nodes.

g.V("A").emit().repeat(__.in('depends')).until(__.inE().count().is(0))

But struggling to extend a query to capture direct children of each vertex. On the image marked as blue ones.

Can anybody help with such a gremlin query?

Here is a query in online editor https://gremlify.com/spml2ktk03 If using the online editor:

  1. Actual: B->A->D->TOP
  2. Expected: B-> A (including info about C) -> D (including info about E) -> TOP
Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Regfor
  • 8,515
  • 1
  • 38
  • 51

1 Answers1

1

You should be able to accomplish what you are looking for by using store() to store all the vertices in the tree and then for each iteration of the repeat you can use sideEffect() to find it's children and store them as well.

g.V().hasLabel('B').store('v').
  repeat(__.in('depends').store('v').
    sideEffect(out('depends').store('v'))).
  until(__.inE().
    count().is(0)).cap('v')

This returns me:

B -> A -> C- > D -> E -> TOP

bechbd
  • 6,206
  • 3
  • 28
  • 47
  • It worked for me! Thank you! I will still test it however Cosmos DB gets timeout error on such queries on some graphs like with 300 vertices. On another graph with 16 vertices works as a charm – Regfor Jul 16 '20 at 15:29