Search code examples
javagremlingremlin-server

Get Gremlin query as a String and execute it in java without submitting it to the GremlinServer


I have a Gremlin query in the String format (for example "g.V()"). I want to execute this String without submitting it to the GremlinServer.

I use the below dependency:

<dependency>
    <groupId>org.apache.tinkerpop</groupId>
    <artifactId>gremlin-driver</artifactId>
    <version>3.3.1</version>
</dependency>

Is there any way?


Solution

  • You can execute Gremlin string directly in GremlinGroovyScriptEngine or through the GremlinExecutor (which just passes the string to the GremlinGroovyScriptEngine but has some additional features to it). Simple pass the Gremlin string to the appropriate eval() method and get back a result from that script evaluation. That's basically what Gremlin Server does internally.

    You will likely need the gremlin-groovy dependency rather than gremlin-driver.