Neptune, Gremlin Java & Bindings

Hey,

I've got a bit of an issue that I'm trying to find a solution for regarding the use of bindings in Gremlin with Neptune.
As stated in the docs, they're not supported. What I'd like to get to is a workaround solution where I can locally apply bindings to a query, convert it to a string and submit it to Neptune with the bindings "applied".

So for instance given the following query:
g.V().hasLabel(my_label_param).limit(results_limit), and bindings my_label_param='airport', results_limit=100
I'd like to submit the following query on Neptune:
g.V().hasLabel('airport').limit(100)

Is there a way perhaps through the gremlin-lang implementation to achieve this? The reason I'd prefer it this way is so that I'm not relying on string replacement where gremlin injection could occur.
Solution
@G.V() - Gremlin IDE (Arthur) with a small modification, it's possible to change the existing translators in 3.x to replace variable placeholders for the values in the bindings. adding this override to GroovyTranslator.DefaultTypeTranslator:
        @Override
        protected Script convertToScript(final Object object) {
            if (object instanceof Bytecode.Binding) {
                return super.convertToScript(((Bytecode.Binding) object).value());
            } else {
                return super.convertToScript(object);
            }
        }

seems to make it work how you want:
gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> b = new org.apache.tinkerpop.gremlin.process.traversal.Bindings()
==>bindings[main]
gremlin> t = g.V().has('name',b.of("n","josh"));[]
gremlin> translator = GroovyTranslator.of("g")
==>translator[g:gremlin-groovy]
gremlin> translator.translate(t).getScript()
==>g.V().has("name","josh")

I guess from your perspective that means you create your own extension to DefaultTypeTranslator then hand it to GroovyTranslator.of("g", <YourTypeTranslator>). i think that would work. The 4.x translators based on the grammar (and not bytecode) are designed to allow this sort of translation more directly, but that's not something you should have to worry about for a while i guess.
Was this page helpful?