Gremlin Graph Traversal: Serialisation

59 views
Skip to first unread message

jacobusl...@gmail.com

unread,
Sep 16, 2017, 12:40:07 PM9/16/17
to Gremlin-users
Hi all,

I am currently using both GraphSON and Gryo to serialise/deserialise a graph. Is it possible to serialise/deserialise a graph traversal? I am catering for a very specific use case, where the graph traversal is generated in Java and should be sent to a Gremlin console.

For example, the bytecode of a specific traversal may look as follows: 

Bytecode traversalByteCode = traversal.asAdmin().getBytecode();
-> [[], [V()]]


How would I go about serialising the Bytecode in Java and Deserialising in Gremlin Console, so that I can ultimately execute the following script:

gremlin> x = JavaTranslator.of(g).translate(bytecodeFromJava);


ADDITIONAL: This is a long shot but does anybody know of a translator that translates Gremlin Machine Traversal Language back into Gremlin, i.e., [GraphStep(vertex,[])] to g.V()

Thank you.

Regards,
Jacobus 

Stephen Mallette

unread,
Sep 18, 2017, 7:32:22 AM9/18/17
to Gremlin-users
You can just create a jackson ObjectMapper and pass the traversal bytecode to it:

gremlin> mapper = GraphSONMapper.build().create().createMapper()
==>org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper@45f24169
gremlin> mapper.writeValueAsString(g.V().out().bytecode)
==>{"sourceInstructions":[],"stepInstructions":[{"operator":"V","arguments":[]},{"operator":"out","arguments":[]}],"bindings":{},"instructions":[{"operator":"V","arguments":[]},{"operator":"out","arguments":[]}]}

You could also do something similar with GryoMapper.


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/cbc38dad-1706-435e-ba46-47c889642da8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stephen Mallette

unread,
Sep 18, 2017, 7:33:22 AM9/18/17
to Gremlin-users
sorry - forgot to address this:

>  This is a long shot but does anybody know of a translator that translates Gremlin Machine Traversal Language back into Gremlin, i.e., [GraphStep(vertex,[])] to g.V()

There is no translation for that. That is just a toString() representation of the steps for basic readability.

jacobusl...@gmail.com

unread,
Sep 18, 2017, 2:21:53 PM9/18/17
to Gremlin-users
Thank you for the reply Stephen, ultimately what I would like to do is send bytecode from Java via REST to the gremlin-server. Is there no way to serialise the Bytecode (can be transferred as a String)?
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.

Stephen Mallette

unread,
Sep 18, 2017, 2:27:41 PM9/18/17
to Gremlin-users
REST does not support bytecode as an input....only Gremlin script strings.

To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/91c9a4e4-2569-4821-8c49-7aae1ae657d6%40googlegroups.com.

jacobusl...@gmail.com

unread,
Sep 18, 2017, 2:53:15 PM9/18/17
to Gremlin-users
Yes, I was curious if I wasn't missing a serialiser somewhere. Thanks for your input :)
Reply all
Reply to author
Forward
0 new messages