0

I'm using a TinkerPop3 Traversal in Java, and I want to update output vertices, edit them and then have that edited vertex not show up again while the traversal continues. Is this possible?

This code:

TinkerGraph tg = TinkerGraph.open();

/**add some vertices and edges**/

GraphTraversalSource gt = tg.traversal();
GraphTraversal<Vertex, Map<String,Object>> traversal = gt.V()
    .has("processed",false).as("initial")
    .out()
    .aggregate("vertices")
    .select("initial","vertices");

while(traversal.hasNext()){
    initial.property("processed",true);
}

Will repeatedly spit out the first vertex that it finds over and over, even though I have set the "processed" property to true.

What can I do to fix or work around this?

Brenden
  • 185
  • 2
  • 10

1 Answers1

3

I'm not sure what's going on in your code example, but if you want to set properties within a traversal, you can do so in a single line of code. See my console session:

gremlin> graph = TinkerGraph.open()
==>tinkergraph[vertices:0 edges:0]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> graph.addVertex('processed',false)
==>v[0]
gremlin> graph.addVertex('processed',false)
==>v[2]
gremlin> graph.addVertex('processed',false)
==>v[4]
gremlin> graph.addVertex('processed',true)
==>v[6]
gremlin> g.V().has('processed',false)
==>v[0]
==>v[2]
==>v[4]
gremlin> g.V().has('processed',false).property('processed',true)
==>v[0]
==>v[2]
==>v[4]
gremlin> g.V().has('processed',false)
gremlin>

You can see that all "processed" properties are now set to false.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • Ugghhh, of course. It also turns out that re-initializing the traversal will have it pick up any changes that you made to the vertices in java. – Brenden Dec 18 '15 at 16:30