Gremlin in Groovy scripts VS The console

1,531 views
Skip to first unread message

agelos.pikoulas

unread,
Jul 4, 2011, 9:37:53 AM7/4/11
to Gremlin-users
Dear Graphistas & Gremliners,

While trying to use Gremlin inside groovy (to which I am very new) in
order to manipulate results in the most convenient manner, I have
encountered various differences in regards to the Gremlin console :

For instance the following code (from https://github.com/tinkerpop/gremlin/wiki/Pattern-Match-Pattern)
:

Table t = new Table();
g.v(1).out('knows').as('x').out('created').as('y').table(t)

works well in the console. On a groovy script "t" is empty.... Trying
to force Gremlin to fill the data, I came up with

g.v(1).out('knows').as('x').out('created').as('y').table(t) >> []

and it worked... Can someone explain what I am doing wrong ?

Also, it would be hugely beneficial if someone who is fluent in both
Groovy and Gremlin can provide a tutorial and use cases of Gremlin
inside proper groovy scripts, with collection manipulations etc :-)

Regards

Marko Rodriguez

unread,
Jul 4, 2011, 9:53:41 AM7/4/11
to gremli...@googlegroups.com
Hi Agelos,

See:

In short, and I just added this to the Wiki above:

When you create a Gremlin path description, what you are really creating is an Iterator. When an Iterator is returned in the Gremlin console (extends Groovy console), the iterator is iterated and the results are ==> printed. When you do the same thing in a Groovy class, there class just have an Iterator, not its iterated results. As such, it is necessary to iterate the iterator. In many cases, a >> -1 does the trick. >> -1 is equivalent to:

while(gremlinPipeline.hasNext()) {
gremlinPipeline.next();
}

Hope that helps,
Marko.

Marko Rodriguez

unread,
Jul 4, 2011, 9:56:18 AM7/4/11
to gremli...@googlegroups.com
Hi again,


Again, mostly everything in Gremlin is an Iterator (in fact, a GremlinPipeline). Thus, when you make an expression, realize you are making an Iterator.

Hope that helps,
Marko.


Begin forwarded message:

Pierre De Wilde

unread,
Jul 4, 2011, 10:07:46 AM7/4/11
to gremli...@googlegroups.com
Hi,

When trying to access Gremlin from Groovy as explained in https://github.com/tinkerpop/gremlin/wiki/Using-Gremlin-through-Groovy:

~$ groovysh
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Groovy Shell (1.8.0, JVM: 1.6.0_26)
Type 'help' or '\h' for help.

groovy:000> com.tinkerpop.gremlin.Gremlin.load()
ERROR groovy.lang.MissingPropertyException:
No such property: com for class: groovysh_evaluate
        at groovysh_evaluate.run (groovysh_evaluate:2)

Pierre

Marko Rodriguez

unread,
Jul 4, 2011, 10:09:06 AM7/4/11
to gremli...@googlegroups.com
Is Gremlin in your classpath?

Pierre De Wilde

unread,
Jul 4, 2011, 10:26:09 AM7/4/11
to gremli...@googlegroups.com
Of course not. Thank you, Marko.

Pierre

2011/7/4 Marko Rodriguez <okram...@gmail.com>

agelos.pikoulas

unread,
Jul 4, 2011, 4:42:50 PM7/4/11
to Gremlin-users
Excellent, it explained a lot - Marko thanks again, I don't feel dumb
anymore!

May I dare suggest/request more examples of Gremlin in Groovy...
closer to the real wild world!

A'


On Jul 4, 4:53 pm, Marko Rodriguez <okramma...@gmail.com> wrote:
> Hi Agelos,
>
> See:https://github.com/tinkerpop/gremlin/wiki/Using-Gremlin-through-Groovy
>
> In short, and I just added this to the Wiki above:
>
> When you create a Gremlin path description, what you are really creating is an Iterator. When an Iterator is returned in the Gremlin console (extends Groovy console), the iterator is iterated and the results are ==> printed. When you do the same thing in a Groovy class, there class just have an Iterator, not its iterated results. As such, it is necessary to iterate the iterator. In many cases, a >> -1 does the trick. >> -1 is equivalent to:
>
>         while(gremlinPipeline.hasNext()) {
>                 gremlinPipeline.next();
>         }
>
> Hope that helps,
> Marko.
>
> http://markorodriguez.com
>
> On Jul 4, 2011, at 7:37 AM, agelos.pikoulas wrote:
>
>
>
>
>
>
>
> > Dear Graphistas & Gremliners,
>
> > While trying to use Gremlin inside groovy (to which I am very new) in
> > order to manipulate results in the most convenient manner, I have
> > encountered various differences in regards to the Gremlin console :
>
> > For instance the following code (fromhttps://github.com/tinkerpop/gremlin/wiki/Pattern-Match-Pattern)

agelos.pikoulas

unread,
Jul 8, 2011, 3:11:01 PM7/8/11
to Gremlin-users
The following is fine in console, throws exception in Groovy :

g = TinkerGraphFactory.createTinkerGraph();
def map = [:];
g.V.outE.inV.groupCount(map) >>-1;

Exception : groovy.lang.MissingMethodException: No signature of
method: com.tinkerpop.blueprints.pgm.impls.tg.TinkerVertex.plus() is
applicable for argument types: (java.lang.String) values: [:]

This one works well in both :

g.V.outE.inV.name.groupCount(map);

What am I missing ?

agelos.pikoulas

unread,
Jul 8, 2011, 3:12:59 PM7/8/11
to Gremlin-users
Using the latest 1.2-SNAPSHOT :-)

On Jul 8, 10:11 pm, "agelos.pikoulas" <agelos.pikou...@gmail.com>
wrote:

Marko Rodriguez

unread,
Jul 8, 2011, 4:08:55 PM7/8/11
to gremli...@googlegroups.com
Hi,

In the Gremlin test cases, there is a test case that is nearly identical to the behavior you specify:



Couple of things, 

1. Does Gremlin build correctly on your computer? Do the tests pass?
2. Do you Gremlin.load() (usually done in static { } call in the class)?
3. outE.inV can be replaced by out (not related to your problem, but just a heads up).

Thanks,

agelos.pikoulas

unread,
Jul 8, 2011, 6:45:39 PM7/8/11
to Gremlin-users


On Jul 8, 11:08 pm, Marko Rodriguez <okramma...@gmail.com> wrote:
> Hi,
>
> In the Gremlin test cases, there is a test case that is nearly identical to the behavior you specify:
>
> http://paste.pocoo.org/show/433628/

Works fine.

>
> Couple of things,
>
> 1. Does Gremlin build correctly on your computer? Do the tests pass?
Yes & yes
> 2. Do you Gremlin.load() (usually done in static { } call in the class)?
Yes - all other things work as expected.

> 3. outE.inV can be replaced by out (not related to your problem, but just a heads up).
I know, that much :-). Its code like
http://groups.google.com/group/gremlin-users/browse_thread/thread/956c1cfc8a0ef30a
that would take me too long to master (wearing too many hats;-)

BTW, I'm sparsely maintaining some Gremlin snippets, mainly copied
from the list. If you like I can add them to a Gremlin wiki ?

Pierre De Wilde

unread,
Jul 8, 2011, 6:51:56 PM7/8/11
to gremli...@googlegroups.com
Hi,

> BTW, I'm sparsely maintaining some Gremlin snippets, mainly copied from the list. If you like I can add them to a Gremlin wiki ?

Good idea if maintained in-sync with snapshot versions.


Thanks,
Pierre

2011/7/9 agelos.pikoulas <agelos....@gmail.com>

Marko Rodriguez

unread,
Jul 9, 2011, 1:05:32 PM7/9/11
to gremli...@googlegroups.com

Hi,

The only thing I can think is wrong is clashing versions in your pom.xml. Can you please post your pom.xml?

Thanks,
Marko.

On Jul 8, 2011 3:45 PM, "agelos.pikoulas" <agelos....@gmail.com> wrote:



On Jul 8, 11:08 pm, Marko Rodriguez <okramma...@gmail.com> wrote:
> Hi,
>

> In the Gremlin test ca...

Works fine.


>
> Couple of things,
>
> 1. Does Gremlin build correctly on your computer? Do the tests pass?

Yes & yes

> 2. Do you Gremlin.load() (usually done in static { } call in the class)?

Yes - all other things work as expected.


> 3. outE.inV can be replaced by out (not related to your problem, but just a heads up).

I know, that much :-). Its code like
    http://groups.google.com/group/gremlin-users/browse_thread/thread/956c1cfc8a0ef30a
that would take me too long to master (wearing too many hats;-)

BTW, I'm sparsely maintaining some Gremlin snippets, mainly copied
from the list. If you like I can add them to a Gremlin wiki ?


>
> Thanks,
> Marko.
>
> http://markorodriguez.com
>
> On Jul 8, 2011, at 1:12 PM, agelos.pikoulas ...

Reply all
Reply to author
Forward
0 new messages