Uploaded image for project: 'TinkerPop'
  1. TinkerPop
  2. TINKERPOP-2050

Add a :bytecode command to Gremlin Console

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Done
    • Affects Version/s: 3.2.9
    • Fix Version/s: 3.4.0, 3.3.5
    • Component/s: console
    • Labels:
      None

      Description

      I am working on a project where there is Java code being written to dynamically generate a Traversal based on a request coming in to an API. You can think of this as a "Traversal Builder."

      The code looks something like this:

      Traversal<Vertex, Vertex> traversal = g.V();
      if (request.searchByAddress == true) {
       traversal.hasLabel("address");
       if (request.address.addressLine1 != null){
       traversal.has("address_line_1", request.address.addressLine1)
       }
      }
      etc.
      

      When that code is being debugged, a traversal.toString() is run on the traversal to see the ouptut. This output is Gremlin bytecode.

      It would be nice to have a way to easily see the Gremlin Groovy that was built so that you could take the Groovy, drop it into Studio, make sure it runs, run a profile() on it, and make sure it's efficient.

      I figured out that you can do this by running this code:

      private String toGremlinGroovyString(Traversal traversal){
       if (traversal == null){
       return null;
       }
      
      Bytecode bc = traversal.asAdmin().getBytecode();
       return GroovyTranslator.of("g").translate(bc);
       }
      

      I think it would be nice to add that as a method on the Traversal class so that it could be used by driver users more easily.

      See comment below for information on the approach taken to help provide support in this area.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                spmallette stephen mallette
                Reporter:
                jhatcher9999 Jim Hatcher
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: