Search code examples
nosqlazure-cosmosdbgremlintinkerpop3

How to fire match query in gremlin . Filter query not working in cosmos db with java driver


I have 2 problem statements with similar approach .Can I put a contains or like query in both to solve my problem in gremlin:

1) Returning vertex 'a' in the following query when the outE() (as depicted in below gremlin query) has label with contains print.

g.V().hasLabel('url').has('name','sw10707').as('a').outE('print').has('forward','states').inV().select('a')

2) Returning all the vertices as stated below which contains print in their edge labels:

g.V().hasLabel('url').has('name','sw10707').as('a').outE('print').has('forward','states').inV()

This query is not working: g.V().hasLabel('url').has('name','sw10707').as('a').outE().filter(it.name.matches('.pri.'))

An issue is already open with .net driver ( but I am not able to find similar functionality with java) : https://github.com/Azure/azure-cosmosdb-dotnet/issues/473


Solution

  • This traversal:

    g.V().hasLabel('url').
      has('name','sw10707').as('a').
      outE().filter(it.name.matches('.pri.'))
    

    requires a lambda expression in filter() and should be written as a Groovy closure:

    g.V().hasLabel('url').
      has('name','sw10707').
      outE().filter{it.name.matches('.pri.')}
    

    Unfortunately, CosmosDB does not support lambdas so your traversal will fail. At this time, there isn't a workaround that I know of short of returning the edges to filter them on the client and then using them to start a second traversal...not great. Hopefully the issue you raised will bring some relief soon.

    Note that I commented on that issue to mention that TinkerPop is considering making those text predicates available - the discussion is here.