Skip to content

Troubleshooting

okram edited this page Jul 16, 2011 · 13 revisions

When working with Gremlin, there may be issues that arise. This section hopes to articulate common problems users have an how to resolve them.

Nearly everything is an iterator

The expression g.V[0] seems like it is returning the first vertex in the graph. However, this statement is in fact creating an iterator/iterable (i.e. a Pipe) that will return the first vertex in the graph when next() is called on it. Thus, use g.V[0]>>1 to return the first vertex in the graph. Better yet, just use g.V>>1. The notation >>1 means “pop off the first object in the iterator and return it.”

In general, when using the Gremlin console, it is not necessary to call next() as the console will automatically iterate it and ==> print the objects of the iterator. However, when using Gremlin in, for example, Java or Groovy, be sure to iterate the pipe. Note that the Gremlin methods provide various shorthand mechanisms for this. For example, >>-1 will “while(hasNext())” and tends to be use consistently.

When the terminal is stuck, use clear

Many times you will misplace a ( or a { and your Gremlin terminal will be “stuck.” To get out of this situation, just type clear to reset the parser.

gremlin> if(true) {
gremlin> 1+2
gremlin> {
gremlin> }
gremlin> 1
groovysh_parse: 24: Ambiguous expression could be a parameterless ...
1 error
gremlin> 1
groovysh_parse: 24: Ambiguous expression could be a parameterless ...
1 error
gremlin> clear
gremlin> 1
==>1

Sometimes function notation is required

There is a single meta method added to Object. This method is _. The _ method denotes the IdentityPipe. If all else fails in terms of trying to get an object to go through a pipe, use _ or _().