Michail Michailidis
Michail Michailidis

Reputation: 12181

Why AddEdgeStep doesn't work after DropStep of edges in the same traversal using Gremlin?

I have this code which essentially updates properties, removes all old IsOfType edges and adds new IsOfType edges (if I remove all the method/class abstraction and make it inline):

traversal = g.V("Entity:633471488:519").as("entity");

//update properties
traversal.property("text", "new text");
traversal.property("description", "new description");

//drop typeEdges
traversal.select("entity").outE("IsOfType").drop();
//even that causes the same issue(!): traversal.select("entity").outE("HasInner").drop();
System.out.println("traversal after type edges deletion: " +traversal);

//make new typeEdges
traversal.V("Entity:996942848:518").as("type-0").addE("IsOfType").from("entity").to("type-0");

System.out.println("traversal after type edges addition: " +traversal);

//storage  
traversal.select("entity").forEachRemaining({})

Everything works (even the drop of existing IsOfType edges). But the creation of the new IsOfType edges doesn't seem to be resulting in new edges on the graph. If I comment out the drop, then creation works fine (!) It is as if the DropStep which is before the addEdgeStep is happening at the end. I even tried to drop other type of edge and it is causing the same issue (!). It might be that implicit transaction handling is deciding to commit when a drop() happens as it is with next(), iterate() and forEachRemaining() ?? If that is the case then drops and creations can't happen within the same transaction using Fluent API which renders it not very useful for real applications :(

Here is the state of the traversals after the deletion and after the additon of two IsOfType edges in my run (I tried both Java and Datastax Studio Console):

traversal after type edges deletion: 
[
   GraphStep(vertex,[Entity:633471488:519])@[entity], 
   AddPropertyStep({value=[Entity], key=[atClass]}), 
   AddPropertyStep({value=[FilmWithSuperCategories aaa], key=[text]}), 
   AddPropertyStep({value=[dffsdfsd f2313], key=[description]}),   
   SelectOneStep(entity)@[entity], 
   VertexStep(OUT,[IsOfType],edge), 
   DropStep
]

traversal after type edges addition: 
[
   GraphStep(vertex,[Entity:633471488:519])@[entity], 
   AddPropertyStep({value=[Entity], key=[atClass]}), 
   AddPropertyStep({value=[FilmWithSuperCategories aaa], key=[text]}), 
   AddPropertyStep({value=[dffsdfsd f2313], key=[description]}), 
   SelectOneStep(entity)@[entity], 
   VertexStep(OUT,[IsOfType],edge), 
   DropStep, 
   GraphStep(vertex,[Entity:996942848:518])@[type-0], 
   AddEdgeStep({~from=[[SelectOneStep(entity)]], ~to=[[SelectOneStep(type-0)]], label=[IsOfType]}), 
   GraphStep(vertex,[Entity:1489781376:516])@[type-1], 
   AddEdgeStep({~from=[[SelectOneStep(entity)]], ~to=[[SelectOneStep(type-1)]], label=[IsOfType]})
]

Edit

From what I read here (http://tinkerpop.apache.org/docs/current/reference/#drop-step)

The drop()-step (filter/sideEffect) is used to remove element and properties from the graph (i.e. remove). It is a filter step because the traversal yields no outgoing objects.

There are no objects being returned so it is not possible to do anything after a drop happens! so I am curious how I can do multiple drops/additions in a single transaction using DSE Graph Fluent API

Thanks!

Upvotes: 2

Views: 322

Answers (1)

Daniel Kuppitz
Daniel Kuppitz

Reputation: 10904

You can wrap your drop in a sideEffect step, e.g.:

g.V(entity1).as("a").sideEffect(outE().filter(inV().is(entity2)).drop()).
  V(entity2).addE("link").from("a")

Upvotes: 4

Related Questions