© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Apache TinkerPopAT
Apache TinkerPop•3y ago•
14 replies
ErickJ

@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
GremlinLangScriptEngine
and the
GremlinGroovyScriptEngine
GremlinGroovyScriptEngine
.

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

I realized today that the
GremlinLangScriptEngine
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'
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
g
https://github.com/apache/tinkerpop/blob/c66cd566941ef7bd34d430828883f9cf79d7442f/gremlin-language/src/main/antlr4/Gremlin.g4#L1876, and enforced in
GremlinLangScriptEngine#eval
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
adds global configuration key to register gremlin traversal sources...
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...
adds global configuration key to register gremlin traversal sources...
GitHub
tinkerpop/gremlin-language/src/main/antlr4/Gremlin.g4 at c66cd56694...
Apache TinkerPop - a graph computing framework. Contribute to apache/tinkerpop development by creating an account on GitHub.
tinkerpop/gremlin-language/src/main/antlr4/Gremlin.g4 at c66cd56694...
Solution
The two
ScriptEngine
ScriptEngine
implementations are not meant to have complete feature parity.
GremlinLangScriptEngine
GremlinLangScriptEngine
does not process arbitrary code. It only processes Gremlin, which I tend to think is a good thing compared to
GremlinGroovyScriptEngine
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
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
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()
g.persons()

might really just compose as:
g.V().hasLabel('person')
g.V().hasLabel('person')

The former won't process in the grammar of
GremlinLangScriptEngine
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
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
tinkerpop/gremlin-javascript/src/main/javascript/gremlin-javascript...
Apache TinkerPop - a graph computing framework. Contribute to apache/tinkerpop development by creating an account on GitHub.
tinkerpop/gremlin-javascript/src/main/javascript/gremlin-javascript...
Jump to solution
Apache TinkerPop banner
Apache TinkerPopJoin
Apache TinkerPop is an open source graph computing framework and the home of the Gremlin graph query language.
1,376Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Is there a way to specify a query execution timeout via the GremlinLangScriptEngine?
Apache TinkerPopATApache TinkerPop / questions
16mo ago
Does the TinkerGraph in-memory database support List cardinality properties for vertices?
Apache TinkerPopATApache TinkerPop / questions
2y ago
neo4j-gremlin plugin support
Apache TinkerPopATApache TinkerPop / questions
3y ago
Does tinker pop support jdk 21?
Apache TinkerPopATApache TinkerPop / questions
4mo ago