0

Currently i have two gremlin queries which will fetch two different values and i am populating in a map. Scenario : A->B , A->C , A->D

My queries below,

  1. graph.V().has(ID,A).out().label().toList()

Fetch the list of outE labels of A .

Result : List(B,C,D)

  1. graph.traversal().V().has("ID",A).outE("interference").as("x").otherV().has("ID",B).select("x").values("value").headOption()

Given A and B , get the egde property value (A->B)

Return : 10

Is it possible that i can combine both there queries to get a return as Map[(B,10)(C,11)(D,12)]

I am facing some performance issue when i have two queries. Its taking more time

PGS
  • 1,046
  • 2
  • 17
  • 38

2 Answers2

0

There is probably a better way to do this but I managed to get something with the following traversal:

gremlin> graph.traversal().V().has("ID","A").outE("interference").as("x").otherV().has("ID").label().as("y").select("x").by("value").as("z").select("y", "z").select(values);
==>[B,1]
==>[C,2]

I would wait for more answers though as I suspect there is a better traversal out there.

Filipe Teixeira
  • 3,565
  • 1
  • 25
  • 45
  • Thanks for the answer. `select(values);` Here the `values` is not getting resolved. Why do we need `select(values)`. Here A has many OutE edges . We need to get OtherV() of all and its edge property value. – PGS Oct 05 '16 at 08:45
  • `select(values);` can actually be omitted if you like. I just do it to get rid of the `z` and `y` labels of the select. This traversal is getting the property on the edge. `select("x").by("value")` this selects `x` which is the edge and `.by("value")` tells it to get the value. – Filipe Teixeira Oct 05 '16 at 09:12
0

Below is working in scala

val b = StepLabel[Edge]()
val y = StepLabel[Label]()
val z = StepLabel[Integer]() 

graph.traversal().V().has("ID",A).outE("interference").as(b)
        .otherV().label().as(y)
        .select(b).values("name").as(z)
        .select((y,z)).toMap[String,Integer]

This will return Map[String,Int]

PGS
  • 1,046
  • 2
  • 17
  • 38
  • 1
    You don't need `otherV` - you traversed `outE`, so to get to the adjacent vertex you can just do `inV`. Use `otherV` when traversing across `bothE` where you need to backtrack to make sure that you don't traverse back to where you came. – stephen mallette Oct 05 '16 at 10:51
  • @stephen mallette Even with both `otherV` and `inV` time taken for fetching the data takes almost the same time. its taking ~19 secs to fetch 4000 vertices each having 10 Edges . Is there any i can still optimize it. – PGS Oct 05 '16 at 14:59
  • `inV` still incurs less overhead, so I would prefer that in any case. not sure i can make it go faster just from a Gremlin perspective. the double `select` seems unnecessary. i would prefer: `g.V().has("ID", "A").outE("interference").as('x').inV().label().as('y').select('y','x').by().by('name')` – stephen mallette Oct 05 '16 at 18:48