Gremlin DSE Graph find path on edge/vertex with multiple properties

135 views Asked by At

i have a case that maybe anyone in here can help me to figure out gremlin query in DSE Graph to find path on edge/vertex with multiple properties.

case

this is my codes in DSE Graph

schema.propertyKey("id").Uuid().ifNotExists().create()`
schema.propertyKey("name").Text().single().create()  
schema.propertyKey("vlan").Text().multiple().create()  
schema.vertexLabel("site").partitionKey('id').properties("id", "name", "vlan").ifNotExists().create()
schema.edgeLabel("linkTo").multiple().properties("id", "name", "vlan").create()
schema.edgeLabel("linkTo").connection("site","site").add()

schema.vertexLabel("site").index("search").search().by("name").by("vlan").asText().add()
schema.vertexLabel("site").index("siteBySiteId").materialized().by("name").add()
schema.vertexLabel("site").index("toLink").outE("linkTo").by("vlan").add()
schema.vertexLabel("site").index("fromLink").inE("linkTo").by("vlan").add()

AA = graph.addVertex(T.label, 'site', 'id', UUID.randomUUID(), 'name', 'AA', 'vlan', '3353', 'vlan', '3563', 'vlan', '2467')
BB = graph.addVertex(T.label, 'site', 'id', UUID.randomUUID(), 'name', 'BB', 'vlan', '3353', 'vlan', '3563')
CC = graph.addVertex(T.label, 'site', 'id', UUID.randomUUID(), 'name', 'CC', 'vlan', '2467')
DD = graph.addVertex(T.label, 'site', 'id', UUID.randomUUID(), 'name', 'CC', 'vlan', '3353', 'vlan', '3563', 'vlan', '2467')

AA.addEdge('linkTo', BB, 'id', UUID.randomUUID(), 'name', 'AA-BB', 'vlan', '3353', 'vlan', '3563')
AA.addEdge('linkTo', CC, 'id', UUID.randomUUID(), 'name', 'AA-CC', 'vlan', '2467')
BB.addEdge('linkTo', DD, 'id', UUID.randomUUID(), 'name', 'BB-DD', 'vlan', '3353', 'vlan', '3563')
CC.addEdge('linkTo', DD, 'id', UUID.randomUUID(), 'name', 'CC-DD', 'vlan', '2467')`enter code here

--------------------
g.V().
  has("site", "name", "AA").  
  emit().
  repeat(timeLimit(200).both("linkTo").        
   filter(bothE("linkTo").                   
     has("vlan",Search.tokenPrefix("3353"))). 
   simplePath()).                             
  has("name", "DD").                     
  path().unfold()

but no success :)

1

There are 1 answers

0
bechbd On

So there are a couple of things going on here:

First in your creation script this line has the name property set to CC instead of DD

DD = graph.addVertex(T.label, 'site', 'id', UUID.randomUUID(), 'name', 'CC', 'vlan', '3353', 'vlan', '3563', 'vlan', '2467')

Second, In Gremlin you cannot add multiproperties (described here) to edges, they are only valid on vertices. As such you will need to change your load script to add parallel edges, one for each vlan property like this:

AA.addEdge('linkTo', BB, 'id', UUID.randomUUID(), 'name', 'AA-BB', 'vlan', '3353')
AA.addEdge('linkTo', BB, 'id', UUID.randomUUID(), 'name', 'AA-BB', 'vlan', '3563')
AA.addEdge('linkTo', CC, 'id', UUID.randomUUID(), 'name', 'AA-CC', 'vlan', '2467')
BB.addEdge('linkTo', DD, 'id', UUID.randomUUID(), 'name', 'BB-DD', 'vlan', '3353')
BB.addEdge('linkTo', DD, 'id', UUID.randomUUID(), 'name', 'BB-DD', 'vlan', '3563')
CC.addEdge('linkTo', DD, 'id', UUID.randomUUID(), 'name', 'CC-DD', 'vlan', '2467')

Since you didn't give much detail on what you were trying to get for an answer I inferred that you were looking for all paths from AA to DD where the vlan is 3353. This can be done is a couple of different ways. If you create the parallel edges such as above you can accomplish this using this Gremlin traversal:

g.V().
  has("site", "name", "AA").
  repeat(
    timeLimit(200).
    bothE("linkTo").
    has("vlan","3353").
    otherV().
    simplePath()
  ).until(has("name", "DD")).
  path().by('name')

If you instead decide that you only want to store the vlan property on the vertices you can get that via Gremlin like this:

g.V().
  has("site", "name", "AA").
  repeat(
    timeLimit(200).
    both("linkTo").
    has("vlan","3353").
    simplePath()
  ).until(has("name", "DD")).
  path().by('name').dedup()

The downside of this is that the path will not contain the edges. If you want the edge information in the path as well you can change the both() step to be a bothE()/otherV() pattern like this:

g.V().
  has("site", "name", "AA").
  repeat(
    timeLimit(200).
    bothE("linkTo").
    otherV().
    has("vlan","3353").
    simplePath()
  ).until(has("name", "DD")).
  path().by('name').dedup()