@GremlinDSL support in the GremlinLangScriptEngine

Hi,

I recently sent a pull-request into the github ArcadeDB repository to add support binding custom TraversalSources to the embedded graph bound in the script engine. ArcadeDb has modes to support both the GremlinLangScriptEngine and the GremlinGroovyScriptEngine.

https://github.com/ArcadeData/arcadedb/pull/1239

I realized today that the GremlinLangScriptEngine went untested, and after trying to add a test I've come to question whether there is any support at all for DSLs in the GremlinLangScriptEngine:

Caused by: javax.script.ScriptException: org.apache.tinkerpop.gremlin.language.grammar.GremlinParserException: Failed to interpret Gremlin query: Query parsing failed at line 1, character position at 6, error message : no viable alternative at input 'g.V().person'


AFAICT from the grammar, the traversalmethod are a list of static tokens, https://github.com/apache/tinkerpop/blob/c66cd566941ef7bd34d430828883f9cf79d7442f/gremlin-language/src/main/antlr4/Gremlin.g4#L178-L286 and the traversal root binding name is hardcoded to g https://github.com/apache/tinkerpop/blob/c66cd566941ef7bd34d430828883f9cf79d7442f/gremlin-language/src/main/antlr4/Gremlin.g4#L1876, and enforced in GremlinLangScriptEngine#eval

This is a bit suprising to find as the DSL documentation doesn't mention these limitations, https://tinkerpop.apache.org/docs/current/reference/#gremlin-javascript-dsl and in the Groovy engine binding the TraversalSource to any token name is allowed.

After reading through the code, I can understand given the current implementation why these limitations might exist, but I'm curiuos if:

  1. have I missed something?
  2. if not, is work planned to support DSLs in the gremlin lang script engine?
  3. if not, can I help?
GitHub
Allows customizing the gremlin script engines traversal sources. This allows clients of the database to register tinkerpop traversal DSLs or customize the traversal strategies.
Motivation
Using tin...
GitHub
Apache TinkerPop - a graph computing framework. Contribute to apache/tinkerpop development by creating an account on GitHub.
Solution
The two ScriptEngine implementations are not meant to have complete feature parity. GremlinLangScriptEngine does not process arbitrary code. It only processes Gremlin, which I tend to think is a good thing compared to GremlinGroovyScriptEngine which will run any arbitrary code and is therefore a bit of a security risk. That said there is some untangling to do in Gremlin Server, ScriptEngines and the grammar and that's the main reason TinkerPop has not yet promoted GremlinLangScriptEngine over its groovy counterpart despite it being more secure and generally more performant than both groovy and bytecode. This is the reason why we don't have much documentation on it.
I believe that you should be able to process Gremlin that originated from a DSL in the GremlinLangScriptEngine but you couldn't do it in the fashion you can with groovy. To understand how it's worth noting that any DSL step is really just a compositions of standard Gremlin steps. in other words, a DSL step like:
g.persons()
might really just compose as:
g.V().hasLabel('person')
The former won't process in the grammar of GremlinLangScriptEngine but the latter will. So, your application can write the former and get the benefits of the DSL but you have to be sure that what is submit to ArcadeDB is the Gremlin produced by that DSL. You can do that in one of several ways, but since you're inquiring about GremlinLangScriptEngine I'll assume this is about sending scripts in which case you'd use your DSL to produce bytecode, then pass that traversal to the translator (https://github.com/apache/tinkerpop/blob/master/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/translator.js) which would then produce a pure Gremlin script to submit with the client, send over HTTP, etc..
GitHub
Apache TinkerPop - a graph computing framework. Contribute to apache/tinkerpop development by creating an account on GitHub.
Was this page helpful?