[
https://issues.apache.org/jira/browse/TINKERPOP-968?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15196763#comment-15196763
]
pieter martin commented on TINKERPOP-968:
-----------------------------------------
Regarding multiple optional labels...
{code}
final TinkerGraph g = TinkerGraph.open();
Vertex a1 = g.addVertex(T.label, "A", "name", "a1");
Vertex b1 = g.addVertex(T.label, "B", "name", "b1");
a1.addEdge("ab", b1);
GraphTraversal gt1 = g.traversal().V(a1).choose(__.out("ab", "bb"),
__.out("ab", "bb"), __.identity()).path();
while (gt1.hasNext()) {
System.out.println(gt1.next());
}
{code}
This will output,
{code}
[v[0], v[2]]
{code}
however what I am looking for with optional semantics is
{code}
[v[0], v[2]]
[v[0]]
{code}
This is because from {{a1}} the optional edge {{bb}} was also traversed
returning {{a1}} as the edge {{bb}} does not exist.
So this can be done using {{union}}
{code}
GraphTraversal gt1 = g.traversal().V(a1).union(
__.choose(__.out("ab"), __.out("ab"), __.identity()),
__.choose(__.out("bb"), __.out("bb"), __.identity())
).path();
while (gt1.hasNext()) {
System.out.println(gt1.next());
}
{code}
returning
{code}
[v[0], v[2]]
[v[0]]
{code}
All of this means that {{optional}} by itself is not powerful enough to
complete the optional semantics. For now it will have to written as
{code}
g.traversal().V(a1).union(
__.optional(__.out("ab")),
__.optional(__.out("bb"))
)
{code}
Do you agree with my assessment?
> Add first class support for an optional traversal
> -------------------------------------------------
>
> Key: TINKERPOP-968
> URL: https://issues.apache.org/jira/browse/TINKERPOP-968
> Project: TinkerPop
> Issue Type: Improvement
> Components: process
> Affects Versions: 3.1.0-incubating
> Reporter: pieter martin
>
> Both SparQL and Cypher use the "Optional" keyword to indicate an optional
> traversal. SQL uses the "left join".
> Gremlin has no first class support for an optional traversal. It can be
> achieved with the choose step but it is verbose, unintuitive and not what the
> choose step is intended for.
> The benefits of optional traversals are many. In particular it makes it
> trivial to load complete subgraphs/trees with one easy to read intuitive
> gremlin statement.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)