0

Am I not using select() properly in my code? When I re-select("pair") for some reason, what it contained originally has been updated after performing some step. Shouldn't what was labeled using as() preserve what was contained?

g.V()
.hasLabel("Project")
.hasId("parentId","childId").as("pair")
.select("pair")
.hasId("parentId").as("parent")
.select("pair") // no longer what it was originally set to

1 Answers1

0

I think this is expected. You (presumably) find two vertices with hasId("parentId","childId") and so the first select("pair") would of course show each vertex. But, then you filter again, hasId("parentId") and kill the traverser that contains the vertex with the id of "childId". It gets filtered away and therefore never triggers the second/last select("pair") step and would only therefore return the one vertex that has the id of "parentId".

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • After some thinking, it makes more sense now. However, I am finding it difficult to think of a way to achieve what I'm trying to do without having to fetch V() again. Do you have any suggestions? I was thinking using next() twice to label them both but that doesn't seem like the ideal approach. – user01110010 Oct 25 '18 at 20:53
  • maybe consider asking a new question that contains more specifics on what you are trying to do, perhaps with some sample data as shown here https://stackoverflow.com/questions/51388315/gremlin-choose-one-item-at-random – stephen mallette Oct 25 '18 at 20:58
  • Thanks for the suggestion. What I asked is completely different from the original question, so I agree. – user01110010 Oct 25 '18 at 21:02