You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by "Robert Dale (JIRA)" <ji...@apache.org> on 2016/10/13 23:35:20 UTC

[jira] [Commented] (TINKERPOP-1506) Optional/Coalesce should not allow sideEffect traversals.

    [ https://issues.apache.org/jira/browse/TINKERPOP-1506?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15573538#comment-15573538 ] 

Robert Dale commented on TINKERPOP-1506:
----------------------------------------

I don't use optional() but I wonder if that's more of a bug. Why execute twice? Shouldn't next() just return the result of hasNext()?  It almost sounds like this bug https://github.com/apache/tinkerpop/pull/346
 
Also, I disagree on coalesce(). It should continue to work as-is.  It's very useful for upsert (update or insert) where you definitely want the second traversal to create an element. I'm open to a better way.  But in general, just because you can shoot yourself in the foot, it doesn't make the tool defective. Maybe it would be better to put a NOTE: in the ref guides about doing such things to make to explicitly clear.

> Optional/Coalesce should not allow sideEffect traversals.
> ---------------------------------------------------------
>
>                 Key: TINKERPOP-1506
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-1506
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: process
>    Affects Versions: 3.1.4, 3.2.2
>            Reporter: Marko A. Rodriguez
>
> 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. 
> {code}
> 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]
> {code}
> 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.'
> {code}
> 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>
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)