repeat() with times() and until()

3,731 views
Skip to first unread message

peter...@gmx.de

unread,
Apr 8, 2016, 7:02:17 AM4/8/16
to Gremlin-users
Hi,

I want to get all paths between two vertices with a certain maximal length (let's say 3). The only solution I came up with for that requires to combine the repeat() step with times(3) and until(hasId(9)). Since repeat() can only have times() OR until(), I combined the two conditions into a single until() using the or() step. This results in the following query:

g.V(1).aggregate("x").repeat(both().where(not(within("x"))).aggregate("x").simplePath()).until(or(hasId(9), loops().is(eq(3)))).hasId(9).path()

which works perfectly fine in GremlinBin:

http://www.gremlinbin.com/bin/view/57077e4c79456

But for some reason I can't use loops() to get the number of iterations when I do the same in the Gremlin Console:

gremlin>  graph = TinkerFactory.createTheCrew(); g = graph.traversal(standard())
==>graphtraversalsource[tinkergraph[vertices:6 edges:14], standard]
gremlin
> g.V(1).aggregate("x").repeat(both().where(not(within("x"))).aggregate("x").simplePath()).until(or(hasId(9), loops().is(eq(3)))).hasId(9).path()
No signature of method: groovysh_evaluate.loops() is applicable for argument types: () values: []
Possible solutions: dump(), grep(), sleep(long), grep(java.lang.Object), is(java.lang.Object), sleep(long, groovy.lang.Closure)
Display stack trace? [yN] y
groovy
.lang.MissingMethodException: No signature of method: groovysh_evaluate.loops() is applicable for argument types: () values: []

Any ideas on why the query doesn't work in the console?

Regards,
Peter

Daniel Kuppitz

unread,
Apr 8, 2016, 7:25:49 AM4/8/16
to gremli...@googlegroups.com
You're probably using an older version of TinkerPop. Anyway, note that your query can be much simpler:


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/da77a335-ed38-46eb-ae36-15189bdede07%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

peter...@gmx.de

unread,
Apr 8, 2016, 7:35:32 AM4/8/16
to Gremlin-users
Yes, I'm using Titan 1.0.0, so TinkerPop 3.0.1, I forgot to mention that.

But thank you very much! Your query does exactly what I wanted, but in a much more elegant way :)

peter...@gmx.de

unread,
Apr 11, 2016, 8:10:39 AM4/11/16
to Gremlin-users
I just tried to include the query in our C# application, but I always get a NullPointerException when I send the query from there to the Gremlin Server. For debugging purposes, I reduced the query to the following which still throws the NullPointerException:

g.V(p0).repeat(both()).times(1)

Here is the log output:

4592861631 [gremlin-server-exec-19] WARN  org.apache.tinkerpop.gremlin.server.op.AbstractEvalOpProcessor  - Exception processing a script on request [RequestMessage{, requestId=df367c1d-0cbb-47fa-971a-d90865695ba6, op='eval', processor='', args={gremlin=g.V(p0).repeat(both()).times(1), bindings={p0=9429299408}, language=gremlin-groovy}}].
java
.lang.NullPointerException

A vertex with the ID of p0 is definitely present in the graph when the query gets executed. Any ideas why I get a NullPointerException here?

Marko Rodriguez

unread,
Apr 11, 2016, 9:46:49 AM4/11/16
to gremli...@googlegroups.com
Hello,

What does g.V(p0) return?

Marko.

peter...@gmx.de

unread,
Apr 11, 2016, 10:35:18 AM4/11/16
to Gremlin-users
Hi Marko,

you mean from the Gremlin Console, right? There it returns the vertex with that ID.

Marko Rodriguez

unread,
Apr 11, 2016, 10:59:44 AM4/11/16
to gremli...@googlegroups.com
Send the query g.V(p0) the same way you send g.V(p0).repeat(both()).times(1). Lets get the repeat() out of the equation. Perhaps its your p0 that is the problem.

Marko.
 

peter...@gmx.de

unread,
Apr 12, 2016, 4:06:54 AM4/12/16
to Gremlin-users
I just tried it with g.V(p0) from my application and got the vertex back. But the problem seems to be related to a combination of repeat() and both(), as the query g.V(p0).repeat(coin(1.0)).times(1) also returns the vertex. Or does the repeat()-step gets optimized away, since I don't use the result?

Marko Rodriguez

unread,
Apr 12, 2016, 9:23:44 AM4/12/16
to gremli...@googlegroups.com
Try one more:

g.V(po).both()

What do you get? NullPointerException?

Marko.

peter...@gmx.de

unread,
Apr 12, 2016, 9:43:20 AM4/12/16
to Gremlin-users
No, I correctly get the vertex of a neighbor.

Marko Rodriguez

unread,
Apr 12, 2016, 9:50:54 AM4/12/16
to gremli...@googlegroups.com
Huh……………. I have no idea.

Please file a bug report with as many details as you can possible add. For instance:

1. Version of TinkerPop.
2. Backend provider.
3. Works locally? but not against Server?
4. g.V(p0).repeat(both()).times(1).explain()
5. Can you make it break with TinkerGraph and no server?

The more information the better as this is really strange to me. I don't have a good idea.

Bummer,
Marko.


peter...@gmx.de

unread,
Apr 13, 2016, 10:15:04 AM4/13/16
to Gremlin-users
Ok, I just created an issue for this:

https://issues.apache.org/jira/browse/TINKERPOP-1262

Unfortunately, I can't do an explain() as we use Titan 1.0.0 which implements TinkerPop 3.0.1 and the explain() step was only introduced in version 3.1.x if I remember correctly.

And no, I can't make it break with TinkerGraph without the Gremlin Server.

I provided the other details in the issue, but tell me if I can help you finding the bug with any more information.
Reply all
Reply to author
Forward
0 new messages