[Tinkerpop3] Gremlin steps with Java

445 views
Skip to first unread message

Dave

unread,
Dec 9, 2014, 11:04:30 AM12/9/14
to gremli...@googlegroups.com
Hi,

I'm using Gremlin and Java and cannot work out the syntax for passing parameters to the Union step. An example would be great.

I've found that almost all of the examples in the docs for Gremlin steps are in Groovy. Since I'm writing in Java trying to work out the parameters for some steps has been challenging given the new lambda syntax and the not-so-clear correlation to Groovy. Using my IDE's auto-complete usually gives me enough of a hint on what is required (usually just a Traverser). If this fails then I read the Tinkerpop source code. 

Adding Java examples in the docs would be great. Is this possible for GA?

Lastly, could someone provide a general rule-of-thumb guide for converting the Groovy syntax into Java syntax using lambdas?   I think I have it but obviously not quite there (since I can't work out the Union step). 

Thanks,
Dave




 

Marko Rodriguez

unread,
Dec 9, 2014, 1:15:36 PM12/9/14
to gremli...@googlegroups.com
Hello,

The mapping between Groovy and Java is pretty simply. I added the following section. Hopefully this helps.


Take care,
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/2fb9b6c1-e949-4a0f-a244-f0a44708a671%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave

unread,
Dec 9, 2014, 11:12:58 PM12/9/14
to gremli...@googlegroups.com
Hi Marko,

Thanks for this. I took the concepts from that section and applied them to the example for the union step and got something like this:-

g.v(1).union(a -> a.get().out().values("name"), b -> b.get().in().values("lang"))

I read in the docs that a copy of the traverser is passed to each parameter but IntelliJ is complaining about the get() method on each branch. I've tried a few other ways but am hitting a wall. I'm sure I will kick myself when I see the answer. Please help.

Thanks,
Dave
P.S. What is the purpose of the "of()" step?   I found it in numerous examples in the docs but could not find an explicit definition.

Marko Rodriguez

unread,
Dec 10, 2014, 9:39:18 AM12/10/14
to gremli...@googlegroups.com
Hey Dave,

Thanks for this. I took the concepts from that section and applied them to the example for the union step and got something like this:-
g.v(1).union(a -> a.get().out().values("name"), b -> b.get().in().values("lang"))

You should look at the docs on how to use union(). Perhaps play with the toy graph in the Gremlin Console a bit to get comfortable with it.

P.S. What is the purpose of the "of()" step?   I found it in numerous examples in the docs but could not find an explicit definition.

In Gremlin3, there is no such thing as _() to represent a "startless" traversal. For one, _ is no longer a legal start character for a variable/class in Java8. Second, _() only worked in Groovy as _() is a meta-method off of Object. This is not possible in Java. In Gremlin2-Java you had to do new GremlinPipeline(). As such, g.of() is the shortest character string I could think of to create a "startless" traversal that will be universal to any Gremlin language variant (Java,Scala,Groovy,etc.). You will see it being used when you have "internal traversals". For example:


HTH,
Marko.








On Tuesday, December 9, 2014 10:15:36 AM UTC-8, Marko A. Rodriguez wrote:
Hello,

The mapping between Groovy and Java is pretty simply. I added the following section. Hopefully this helps.


Take care,
Marko.


On Dec 9, 2014, at 9:04 AM, Dave <da...@davidcrouchcustomhomes.com> wrote:

Hi,

I'm using Gremlin and Java and cannot work out the syntax for passing parameters to the Union step. An example would be great.

I've found that almost all of the examples in the docs for Gremlin steps are in Groovy. Since I'm writing in Java trying to work out the parameters for some steps has been challenging given the new lambda syntax and the not-so-clear correlation to Groovy. Using my IDE's auto-complete usually gives me enough of a hint on what is required (usually just a Traverser). If this fails then I read the Tinkerpop source code. 

Adding Java examples in the docs would be great. Is this possible for GA?

Lastly, could someone provide a general rule-of-thumb guide for converting the Groovy syntax into Java syntax using lambdas?   I think I have it but obviously not quite there (since I can't work out the Union step). 

Thanks,
Dave




 

--
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/2fb9b6c1-e949-4a0f-a244-f0a44708a671%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
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.

Dave

unread,
Dec 10, 2014, 2:11:54 PM12/10/14
to gremli...@googlegroups.com
Hi Marko,

g.of()  - got it. It appeared similar to _() but I didn't know if it had additional meaning. 

It just occurred to me to look at the Union step test harness, which gave me what I needed. At one point I was trying g.of().out() but needed g.<Vertex>of().out()   (so close!). This detail got lost in my learning curve with the new traverser concept.

Under the covers I'm assuming a new traverser is created for every branch of the Union step, which I believe makes my use of lamdas incorrect?   I was using the Jump step as a guide but see that it is different to the other branch steps (Union, Local, Choose, Match) because conceptually it is not executing parallel paths. Is this assumption correct?    .... just trying to improve my knowledge.

Thanks for your help.

Regards,
Dave

Marko Rodriguez

unread,
Dec 10, 2014, 7:58:07 PM12/10/14
to gremli...@googlegroups.com
Hi,

It just occurred to me to look at the Union step test harness, which gave me what I needed. At one point I was trying g.of().out() but needed g.<Vertex>of().out()   (so close!). This detail got lost in my learning curve with the new traverser concept.

Ah, yes -- g.<Vertex>of(). Typecasting. And Java8 is more strict on typing.

Under the covers I'm assuming a new traverser is created for every branch of the Union step, which I believe makes my use of lamdas incorrect?   I was using the Jump step as a guide but see that it is different to the other branch steps (Union, Local, Choose, Match) because conceptually it is not executing parallel paths. Is this assumption correct?    .... just trying to improve my knowledge.


Uh… under the covers the traverser is .split() and put into the internal traversals via Traversal.addStart().

There is no solid reason why jump() doesn't use an "internal traversal". It could be:

g.V.loop(10, g.of().out()).name

In essence, loop over out() 10 times. When were first started down the TP3 road I was super hesitant about 'internal traversals' because they could not be converted to OLAP execution. However, over time, we developed the concept of "linearization" which allows you to write a nested traversal as a single line with lots of jump() calls -- i.e. goto statements. In other words, an OLAP specific compiler.

Something we can reconsider. Do we like:

g.V.until(t -> t.get().value('name').equals('marko'), g.of().out())
g.V.until(g.of().out(), t -> t.get().value('name').equals('marko'))

The first is "while/do" and the second is "do/while". Currently, this is implemented as:

g.V.until('a', t -> t.get().value('name').equals('marko')).out().as('a')
g.V.as('a').out().jump('a', t -> !t.get().value('name').equals('marko'))

Same character length, …………the prior uses "internal traversals" and the latter uses as().

Thank you for your thoughts,
Marko.




Marko Rodriguez

unread,
Dec 11, 2014, 9:44:02 AM12/11/14
to gremli...@googlegroups.com
Hi Dave,

Expanding on this email about looping constructs, I thought you might like to contribute thoughts to this newly created issue:

Take care,
Marko.

Dave

unread,
Dec 11, 2014, 8:49:13 PM12/11/14
to gremli...@googlegroups.com
Thanks, Marko. I just added a comment to #411. I do like the evolution that is being enabled by internal traversals. I never did like using the "goto" statement-like branching with the jump, back and as steps. Brought back memories of programming in Fortran and Basic (OK, I'm older than you but not that old ;-).

Regards,
Dave

Marko Rodriguez

unread,
Dec 12, 2014, 10:39:37 AM12/12/14
to gremli...@googlegroups.com
Hi Dave,

Great. This is the kind of feedback we are looking for and why we are still in the TP3 Milestones phase. We can always add more steps in the future, but changing names or patterns for existing steps will be difficult once GA come out. I've been putting out lots of "should we rename this step?"-style issues lately. If you have the time and opinion, please provide your insights to those as well as for any other steps you might like to see (though again we can always add in the future so that is no a rush) or change.

Thank you Dave,
Marko.
Reply all
Reply to author
Forward
0 new messages