Date
1 - 6 of 6
How to filter out step 3 vertex list based on step 1 vertex
Ronnie
Hi,
Assuming following schema
VertexA--edgeAB-->VertexB
VertexA--edgeAC-->VertexC
VertexC--edgeCB-->VertexB
Traversal
step 1: start with VertexB,
step 2: traverse edgeAB to find connected VertexA,
step 3: traverse edgeAC to find connected VertexC
step 4: how to filter out VertexC which are not connect to VertexB from step 1 ?
Gremlin queries that i tried:
Expected result: list of VertexC vertices which are connect back to the same VertexB vertex from step 1
Actual result: empty
Any pointers to why these gremlin queries don't work as expected?
Thanks,
Ronnie
Assuming following schema
VertexA--edgeAB-->VertexB
VertexA--edgeAC-->VertexC
VertexC--edgeCB-->VertexB
Traversal
step 1: start with VertexB,
step 2: traverse edgeAB to find connected VertexA,
step 3: traverse edgeAC to find connected VertexC
step 4: how to filter out VertexC which are not connect to VertexB from step 1 ?
Gremlin queries that i tried:
g.V().hasLabel("VertexB").as("B").in("edgeAB").out("edgeAC").where(__.out("edgeCB").is("cert"))
g.V().hasLabel("VertexB").as("B").in("edgeAB").out("edgeAC").where(__.out("edgeCB").hasId(__.select("cert").id()))
Expected result: list of VertexC vertices which are connect back to the same VertexB vertex from step 1
Actual result: empty
Any pointers to why these gremlin queries don't work as expected?
Thanks,
Ronnie
Boxuan Li
Hi Ronnie,
Not sure if it's optimal but this should work:
You can also do this in two steps:
Best,
Boxuan
Not sure if it's optimal but this should work:
g.V().hasLabel("VertexB").as("B").in("edgeAB").out("edgeAC").as("C").out("edgeCB").as("B2").where("B", eq("B2")).select("C")
You can also do this in two steps:
b = g.V().hasLabel("VertexB").as("B").next()
g.V(b).in("edgeAB").out("edgeAC").where(out("edgeCB").is(b))
FYI, for general gremlin query questions, you can also ask in the gremlin-users mailing list: https://groups.google.com/g/gremlin-usersBest,
Boxuan
Ronnie
Thanks Boxuan! I tried the single query and that worked accurately!
On the other hand, I am still trying to figure out why the where traversal e.g. where(__.out("edgeCB").is("B")) didnt work. Is it because "B" is considered as literal instead of step label?
Also thanks for pointing me to the gremlin-users group.
Thanks!
Ronnie
On the other hand, I am still trying to figure out why the where traversal e.g. where(__.out("edgeCB").is("B")) didnt work. Is it because "B" is considered as literal instead of step label?
Also thanks for pointing me to the gremlin-users group.
Thanks!
Ronnie
Boxuan Li
That’s a great question! To be honest I am not sure about the reason. My assumption is the __.out("edgeCB").is("B") is an anonymous child traversal within where() step, and thus it has no access to the label “B” which is defined in the outer traversal.
I am not sure if my understanding is correct. It might be a better idea to ask in the gremlin-users group.
Cheers,
Boxuan
「Ronnie via lists.lfaidata.foundation <rputhukkeril=qualys.com@...>」在 2021年7月9日 週五,上午3:07 寫道:
Thanks Boxuan! I tried the single query and that worked accurately!
On the other hand, I am still trying to figure out why the where traversal e.g. where(__.out("edgeCB").is("B")) didnt work. Is it because "B" is considered as literal instead of step label?
Also thanks for pointing me to the gremlin-users group.
Thanks!
Ronnie