gremlinjanusgraphjavascript-enginegroovyscriptengine

How to replace tinkerpop imports by janus-graph imports during initialization of gremlin groovy script engine?


I initialize gremlin-script-engine with janus-plugin in this way:

GremlinScriptEngineManager engineManager = new DefaultGremlinScriptEngineManager();
engineManager.addPlugin(JanusGraphGremlinPlugin.instance());
engine = engineManager.getEngineByName("gremlin-groovy");

Engine normally evaluates queries with some janus elements (e.g. Multiplicity.ONE2MANY):

qu = "mgmt.makeEdgeLabel('"+ TEST_EDGE_LABEL+"').multiplicity(ONE2MANY).make();";
engine.evalWithManagementTransaction(qu);

... but for the query:

qu = "mgmt.makePropertyKey('"+TEST_PROPERTY_KEY+"')"
        + ".dataType(String.class).cardinality(Cardinality.SINGLE).make();";

I get:

MissingPropertyException: No such property: SINGLE for class: org.apache.tinkerpop.gremlin.structure.VertexProperty$Cardinality

It seems that the script-engine tries to use org.apache.tinkerpop.gremlin.structure.VertexProperty$Cardinality and not janus one org.janusgraph.core.Cardinality.

PS: If I use full name of class org.janusgraph.core.Cardinality.SINGLE or only value of Cardinality enum (e.g. just SINGLE) in query then all works fine.

How could I remove tinkerpop imports or force script-engine to use janus imports from plugin... or it makes sense to change gremlin-queries?


Solution

  • In the console you can do and alias:

    gremlin> import org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality as Card
    gremlin> Card
    ==>class org.apache.tinkerpop.gremlin.structure.VertexProperty$Cardinality
    

    But I don't think that will work for the Gremlin ScriptEngine for some reason. I don't think we've exposed the ability to alias there.

    I think you would have to use the full class name of org.janusgraph.core.Cardinality.SINGLE. Of course, I would wonder why you would be doing schema modifications this way. Typically, schema modifications are administrative functions that you would handle outside of the GremlinScriptEngine and more directly in your code or in the console as a script.