Uploaded image for project: 'TinkerPop'
  1. TinkerPop
  2. TINKERPOP-1506

Optional/Coalesce should not allow sideEffect traversals.

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.1.4, 3.2.2
    • Fix Version/s: 3.3.0
    • Component/s: process
    • Labels:
      None

      Description

      It took me a long time to realize what was wrong with a traversal I wrote that used optional(blah.sideEffect.blah). optional() maps to ChooseStep under the hood and the provide traversal is first tested for a hasNext(). If so, the it plays itself out. The problem is that if there is a side-effect in the traversal child, then it gets executed twice.

      gremlin> g = TinkerGraph.open().traversal()
      ==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
      gremlin> g.inject(1).optional(addV('twin'))
      ==>v[1]
      gremlin> g.V().valueMap(true)
      ==>[id:0,label:twin]
      ==>[id:1,label:twin]
      

      We should NOT allow optional() to have SideEffectStep steps in it so as not to cause unexpected behavior. StandardVerificationStrategy can analyze and throw an exception if necessary.

      Also, coalesce() has a similar problem, though perhaps it can be a useful 'technique.'

      gremlin> g = TinkerGraph.open().traversal()
      ==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
      gremlin> g.inject(1).coalesce(addV('twin1').limit(0), addV('twin2'))
      ==>v[1]
      gremlin> g.V().valueMap(true)
      ==>[id:0,label:twin1]
      ==>[id:1,label:twin2]
      gremlin>
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                okram Marko A. Rodriguez
                Reporter:
                okram Marko A. Rodriguez
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: