Search code examples
javagremlintinkerpopamazon-neptune

Tinkerpop traversal to string


Is it possible to get from a traversal a gremlin request ready to use ? As JPA do with the log in debug level. For tinkerpop the debug give the traversal.toString() which is time consuming to transform in a request.


Solution

  • You can translate a traversal back into a textual form using the GroovyTranslator class from Apache TinkerPop.

    If you had a traversal defined as follows

     Traversal t = 
          g.V().has("airport","region","US-TX").
                local(values("code","city").
                fold());
    

    You can convert that back to a text string using

    String query;
    query = GroovyTranslator.of("g").
            translate(t.asAdmin().getBytecode());
        
    System.out.println("\nResults from GroovyTranslator on a traversal");
    System.out.println(query);
    

    There are further examples here:

    https://github.com/krlawrence/graph/blob/master/sample-code/RemoteWriteText.java