0

I want to modify some property for all vertices connected via edges with some label in JanusGraph using Gremlin in Java. I tried the following:

public void setAllProperties(JanusGraphTransaction janusGraphTransaction) {
    GraphTraversal<Vertex, Vertex> traversal = janusGraphTransaction.traversal().V();
    traversal.has("SomeLabel", "SomeProperty", 0)
            .repeat(out("SomeEdgeLabel"))
            .property("SomeProperty", true)
            .until(outE("SomeEdgeLabel").count().is(0));
}

But no vertices are modified. I tried googling for modifying properties while traversing using repeat... until but without any success. Any suggestions?

Maciej Mościcki
  • 686
  • 1
  • 9
  • 13

1 Answers1

1

First, I think you need to iterate() your traversal - see tutorial - thus:

public void setAllProperties(JanusGraphTransaction janusGraphTransaction) {
    GraphTraversal<Vertex, Vertex> traversal = janusGraphTransaction.traversal().V();
    traversal.has("SomeLabel", "SomeProperty", 0)
            .repeat(out("SomeEdgeLabel"))
            .property("SomeProperty", true)
            .until(outE("SomeEdgeLabel").count().is(0)).iterate();
}

then, move the property() inside the repeat():

public void setAllProperties(JanusGraphTransaction janusGraphTransaction) {
    GraphTraversal<Vertex, Vertex> traversal = janusGraphTransaction.traversal().V();
    traversal.has("SomeLabel", "SomeProperty", 0)
            .repeat(out("SomeEdgeLabel").property("SomeProperty", true))
            .until(outE("SomeEdgeLabel").count().is(0)).iterate();
}

property() is not a type of Map step - it just passes the Vertex through so your traversal keeps working.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • It works if I emit vertices then modify them in stream/list but the number of vertices will be extremely large - they won't fit into the memory. That's way I need to edit them while traversing. – Maciej Mościcki Aug 02 '18 at 15:15
  • 1
    updated answer based on your comment. i think that's what you want anyway. i think you can drop the `until()` in this case as well – stephen mallette Aug 02 '18 at 16:18