You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by "Daniel Kuppitz (JIRA)" <ji...@apache.org> on 2015/06/09 00:05:01 UTC
[jira] [Commented] (TINKERPOP3-715) [Proposal] Do we need a
optional(traversal) like in TinkerPop2?
[ https://issues.apache.org/jira/browse/TINKERPOP3-715?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14577937#comment-14577937 ]
Daniel Kuppitz commented on TINKERPOP3-715:
-------------------------------------------
It's not the first time that this question comes up, but - Nah, please don't. {{.optional()}} never worked as expected. Your sample can be solved using {{.union()}}:
{code}
g.V(x).union(
out('rated').aggregate('userLibrary').is(null), // .aggregate() will collect all vertices, but .is(null) will never emit an element
outE('rated').has('stars', gte(4)).inV(). // union-traversals are processed in their given order, thus 'userLibrary' will be available in the 2nd union-traversal
inE('rated').has('stars',gte(4)).inV().
outE('rated').has('stars',gte(4)).inV().where(not(within('userLibrary')))).groupCount()
{code}
Not tested, but it should work.
> [Proposal] Do we need a optional(traversal) like in TinkerPop2?
> ---------------------------------------------------------------
>
> Key: TINKERPOP3-715
> URL: https://issues.apache.org/jira/browse/TINKERPOP3-715
> Project: TinkerPop 3
> Issue Type: New Feature
> Reporter: Marko A. Rodriguez
>
> In TinkerPop2 we had {{optional()}}. It allowed the traverser to go down the {{optional}}-branch and its results were only used for their sideEffects. For instance:
> {code}
> g.V(x).optional(out('rated').aggregate('userLibrary'))
> .outE('rated').has('stars',gte(4)).inV()
> .inE('rated').has('stars',gte(4)).inV()
> .outE('rated').has('stars',gte(4)).inV().where(not(within('userLibrary')))
> .groupCount()
> {code}
> To do this in TinkerPop3, we would do:
> {code}
> g.V(x).sideEffect(v -> g.V(v.get()).out('rated').aggregate('userLibrary').iterate())
> .outE('rated').has('stars',gte(4)).inV()
> .inE('rated').has('stars',gte(4)).inV()
> .outE('rated').has('stars',gte(4)).inV().where(not(within('userLibrary')))
> .groupCount()
> {code}
> ... :/ ... should we add {{optional}} back in the mix? It would be like {{.as('a').local(...).select('a')}} but it would not care if the nested traversal returned a result or not.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)