gremlingraph-databasesazure-cosmosdb-gremlinapi

Gremlin Customized Output using project


enter image description here

gremlinify: https://gremlify.com/l3gujyc2e5 pls execute Query 2 and 2.1 to see the difference.

I have an acyclic uni-directional graph in Cosmos Graph Db.

My graph has 2 types of vertices:

Every processor takes 1 or more items and produces 1 or more items.

Problem Statement: given some itemsList, disabledProcessorsList, traverse the graph starting from items in the itemsList until the path is exhausted or when we reach any processor in the disabledProcessorsList.

Eg:

itemsList : 'i6'

disabledProcessorsList: 'p12','p13','p14'

Query:

g.V().has('ItemDefinition','ItemName', within('i26'))
.until(__.outE().count().is(0))
.repeat(out().hasLabel('ProcessorDefinition')
.not(or( has('ProcessorName', within('p12','p13','p14'))))
.store('ProcessorsInPath').out())
.select('ProcessorsInPath').unfold().dedup()
.project('Processor', 'InputItems', 'OutputItems')
.by(__.valueMap('ProcessorName').select('ProcessorName'))
.by(__.in().values('ItemName').order().fold())
.by(__.out().values('ItemName').order().fold())

In the above query while traversing down i'm just collecting the vertices labelled ProcessorDefinition and listing all its inputs and outputs

Expected output for the above query:

[
  {
    "Processor": [
      "p11"
    ],
    "InputItems": [
      "i25",
      "i26",
      "i27",
      "i28"
    ],
    "OutputItems": [
      "i29"
    ]
  }
]

Just FYI.. Even if p13 is not in disabledProcessors the expected output should be the same as p11 cannot reach p13 without traversing through p12 which is disabled

Actual output for the above query:

[]

How do I write the query to get the expected output?

Thanks!


Solution

  • Using cap() instead of store() fixed my issue. Looks like it has something to do with the lazy evaluation of store().

    cap() will force an eager evaluation of all previous step, pretty similar to barrier(). Indeed you can see cap(xxx) as a shorthand for barrier().select(xxx)

    source: https://www.datastax.com/blog/gremlin-recipes-7-variables-handling

    https://gremlify.com/aamt3fv745