gremlingremlinnet

Is there any execution order guarantee for SideEffect in Gremlin


I have a bit of Gremlin.Net code that copies a Vertex into a new one, marks the old edge as 'ended', links the new vertex (clone) and updates some of the properties in it. Ignoring my own DSL code in the snippet, my question is, can I rely on the order of these SideEffects? I need the 'update' step to run last

...AddV().Property("label", __.Select<Vertex>("existing").Label()).As("clone") // new vertex
                .SideEffect(__
                    .Select<Vertex>("existing").Properties<VertexProperty>().As("p")
                    .Select<Vertex>("clone")
                    .Property(__.Select<VertexProperty>("p").Key(), __.Select<VertexProperty>("p").Value<object>()))
                .SideEffect(__
                    .Select<Vertex>("existing").InE(DbLabels.ComponentEdge).As("ine")
                    .MarkToDate(operationTime)
                    .AddE(linkedEdgeLabel).From("parent").To("clone")
                    .MarkFromDate(operationTime))
                .SideEffect(__
                    .Select<Vertex>("clone").UpdateVertexPropertiesUnchecked(propertyDict));

If not, is the a better way to do this?


Solution

  • I am not sure if it has ever been documented that they are executed in order but I think it is a reasonable assumption as queries such as the one below absolutely need to execute in sideEffect step order. I am not sure if there are any cases where a Gremlin Strategy might rewrite/re-order that query. If I find anything I will update this answer.

    gremlin> g.V(44).values('runways')
    ==>3
    
    gremlin> g.V(44).sideEffect(properties('runways').drop()).sideEffect(property(set,'runways',99)).values('runways')
    ==>99
    
    gremlin> g.V(44).values('runways')
    ==>99     
    

    At the end of the day probably always best to check with the provider of the graph store you are using. That said, within the TinkerPop community we are working on significantly improving the documentation around the semantics of each Gremlin step and this is definitely something we should clarify there.