[TinkerPop3] Branch-Step Redesign -- union() and choose() are simply extension.

218 views
Skip to first unread message

Marko Rodriguez

unread,
Jan 22, 2015, 8:27:24 PM1/22/15
to gremli...@googlegroups.com, d...@tinkerpop.incubator.apache.org
Hi,

Daniel and I have been working this afternoon and evening on making BranchStep better. Bob Briody mentioned earlier that as()-based navigation is nearly gutted save for back() and branch(). I was thinking about branch() and now that we can support nested traversals on OLAP, we don't need "teleport" capabilities as we no longer need to linearize traversals -- and we don't want the headache of arbitrary jumping. As such, is there an abstraction to ChooseStep and UnionStep, where ChooseStep == pick one branch and UnionStep == pick all branches, then lets do it --- that generalization is now BranchStep:


And you can see how simple ChooseStep and UnionStep are now:


Tada! Moreover, notice ForkHolder. What is that all about? I'm glad you asked ---


I don't like the name fork(), but now you no longer have to create that lame 'ol Map<M,Traversal> which is ugly in Java… Now you can just choose().fork().fork().fork(). Likewise for branch() and union(), though because union() is a fork on Pick.any, the var args union(traversal…) remains. Again, Daniel and I couldn't come up with a better name for fork(), so if someone has an idea, bust it out.

Here are the docs:
http://www.tinkerpop.com/docs/3.0.0-SNAPSHOT/#choose-step (lots of change here. notice no more Map<>….schweeeeet)
http://www.tinkerpop.com/docs/3.0.0-SNAPSHOT/#union-step (nothing changed here because we kept the traversal var args method)

Finally, Daniel did some ballin' work on XOR computations using the new branch() work. We are on the precipice of unifying two seemingly distinction computations islands --- branch() and match().

Stoked. Enjoy!,
Marko.

Daniel Kuppitz

unread,
Jan 22, 2015, 8:51:31 PM1/22/15
to gremli...@googlegroups.com, d...@tinkerpop.incubator.apache.org
Ok, here comes the code part of this story. We can now do OR (union), AND (intersect) and even XOR (difference). Here's how *:

// condition #1: age >= 29
// condition #2: age <= 29
 
g = TinkerFactory.createModern()
 
//
// OR (union)
//
gremlin> g.V().union(__.has("age", lte, 29), __.has("age", gte, 29)).dedup()
==>marko 29
==>vadas 27
==>josh 32
==>peter 35
//
// AND (intersect)
//
gremlin> g.V().has(label, "person").union(
__.has("age", lte, 29).store("x"),
__.has("age", gte, 29).store("y")).retain("x").retain("y").dedup()

==>marko 29
 
//
// XOR (difference)
//
gremlin> g.V().has(label, "person").union(
__.has("age", lte, 29).store("x"),
__.has("age", gte, 29).store("y")).fold().unfold().union(
__.except("x"),
__.except("y"))
==>vadas 27
==>josh 32
==>peter 35
//
// XOR (alternative using choose())
//
gremlin> g.V().has(label, "person").choose { it.value("age").compareTo(29) /* <- that's actually cheated */ }.
fork(-1, __.store("x")).
fork( 0, __.store("x").store("y")).
fork( 1, __.store("y")).fold().unfold().union(__.except("x"), __.except("y"))
==>vadas 27
==>josh 32
==>peter 35

* I extended each traversal by .map { it.get().value("name").padRight(6) + it.get().value("age") } to get more meaningful results.

Cheers,
Daniel


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/DA37217A-F029-4CBA-A7BC-99DC5A8BA3FD%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Matt Frantz

unread,
Jan 23, 2015, 1:09:55 PM1/23/15
to gremli...@googlegroups.com, d...@tinkerpop.incubator.apache.org
On Thursday, January 22, 2015 at 5:27:24 PM UTC-8, Marko A. Rodriguez wrote:
[snip]
 
I don't like the name fork(), but now you no longer have to create that lame 'ol Map<M,Traversal> which is ugly in Java… Now you can just choose().fork().fork().fork(). Likewise for branch() and union(), though because union() is a fork on Pick.any, the var args union(traversal…) remains. Again, Daniel and I couldn't come up with a better name for fork(), so if someone has an idea, bust it out.
[snip]

How about "choice"?  It seems to pair nicely (and grammatically) with "choose". 

Marko Rodriguez

unread,
Jan 23, 2015, 1:19:59 PM1/23/15
to gremli...@googlegroups.com, d...@tinkerpop.incubator.apache.org
Hi Matt,

We just changed it to option().
branch().option().option().option()
choose().option().option().option()
The problem with "choice" is that is seems too tied to choose()-step.

What do you think of option()?

Thanks,
Marko.

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.

Matt Frantz

unread,
Jan 23, 2015, 1:49:32 PM1/23/15
to gremli...@googlegroups.com, d...@tinkerpop.incubator.apache.org
On Friday, January 23, 2015 at 10:19:59 AM UTC-8, Marko A. Rodriguez wrote:
Hi Matt,

We just changed it to option().
branch().option().option().option()
choose().option().option().option()
The problem with "choice" is that is seems too tied to choose()-step.

What do you think of option()?


Yes, "option" works for me.  After I suggested "choice", I realized I hadn't considered the other use cases (branch, union).  I think "case" also has merit.  How important is it to avoid conflict with reserved words in various languages? 

Daniel Kuppitz

unread,
Jan 26, 2015, 3:57:25 PM1/26/15
to gremli...@googlegroups.com, d...@tinkerpop.incubator.apache.org
Hi Matt,

it's very important to avoid conflicts with reserved keywords (of JVM languages). It can be quite annoying; I bet we already needed every keyword that currently exists (for, while, switch, case, to name a few) :)

Cheers,
Daniel
Reply all
Reply to author
Forward
0 new messages