Search code examples
python-3.xtinkerpop3

Gremlin-Python Bindings


I started to study about bindings and it seemed that it will improve the speed of commonly executed query and I went ahead to try it out.

My query was pretty simple:

g.V(('id', 1))

but its not working

File "/home/galaxia/PycharmProjects/helloworld/venv/lib/python3.5/site-packages/gremlin_python/driver/protocol.py", line 106, in data_received
    "{0}: {1}".format(status_code, data["status"]["message"]))
gremlin_python.driver.protocol.GremlinServerError: 597: startup failed:
Script19.groovy: 1: expecting ')', found ',' @ line 1, column 10.
   g.V(('id', 1))
            ^

I feel i followed the syntax mentioned in the doc. Did I miss something?

enter image description here


  • python3
  • tinkerpop 3.3.1
  • neo4j 3.3

Solution

  • I need to clarify a some things first. Are you sending g.V(('id', 1)) as a script to Gremlin Server like:

    client = Client('ws://localhost:8182/gremlin', 'g', pool_size=1)
    client.submit("g.V(('id', 1))").all().result()
    

    or are you using a remote traversal like:

    >>> graph = Graph()
    >>> g = graph.traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
    >>> g.V(('id', 1))
    

    If you are sending scripts, then you aren't using bindings properly. That documentation you linked to is for the latter approach and if you tried the former with that syntax I would imagine you getting that particular error. If you want to use bindings with the scripts then you would want to do this:

    client = Client('ws://localhost:459408182/gremlin', 'g', pool_size=1)
    client.submit("g.V(id)", {'id':1}).all().result()
    

    For that kind of usage you will see a noticeable improvement in performance.

    Now, if you were doing the latter and using remote traversals, then the first thing to understand is that the documentation isn't completely clear on what the performance improvement is. At this time, the performance enhancement only comes with bindings if your traversal includes a lambda. That was supposed to be a temporary limitation, but it was never implemented further (though it is something being examined now as for this writing). So, since your traversal (in this example) has no lambda you won't see a performance boost for using bindings.

    That said, your traversal above should still work in this context and you should not be getting an error. I'm going to assume that you were submitting scripts though when you got this error as I can't think of how else you could have ended up with this output otherwise. If that is not the case, I can try to expand further.