Printing the results of Pipe/Pipeline/GremlinPipeline in Java

815 views
Skip to first unread message

pShah

unread,
May 4, 2012, 2:32:29 PM5/4/12
to gremli...@googlegroups.com
  I am trying my best to understand the deifference between:  Pipe, Pipeline, GremlinPipeline and how to print the results for each if possible.
 
  *****************************
  I am looking for Java specifc advice/code/samples. 
  I know that the Gremlin shell just does things, but since eventually I want everything coded in Java thats were I am starting too.
  *****************************

  As I understand:

  1.  Pipe is a datflow or "mini functions" to work on Vertices (or can it work on Edges too?)
  2.  Pipeline can be used to specify the order of Pipes and how things should be processed.
  3.  Where does GremlinPipeline fit in?  If we have Pipeline what is the point of GremlinPipeline (I am sure there is a good reason for it, but I don't get it)?
  4.  I also see some examples with "pipe.start" and some with "pipe.setStarts".  What is the difference?

  Code composed from examples:
        IndexableGraph g = TinkerGraphFactory.createTinkerGraph();
        GremlinPipeline pipe = new GremlinPipeline(g.getVertex(1)).out("knows");
        System.out.println("Vertex Count: " + pipe.count());

   This works fine, I used GremlinPipeline, becuase that's what I saw in the example.
   How do I go about printing the names in output as:

   Marko knows: (hopefully both values from the graph and not hardcoded, so that later I can also try all outer edges)
   Name: Josh, 32
   Name: Vadas, 27

 
Thanks

  
 



Marko Rodriguez

unread,
May 4, 2012, 2:45:02 PM5/4/12
to gremli...@googlegroups.com
Hello,

> I am trying my best to understand the deifference between: Pipe, Pipeline, GremlinPipeline and how to print the results for each if possible.

Pipe: a "mini function" that can be chained together with other Pipes to do some larger function.
Pipeline: a chain of Pipes with lots of extra helper methods beyond the Pipes interface.
GremlinPipeline: a fluent-pipeline representation for doing graph traversals + whatever is in Pipes.

Note that Pipes (http://pipes.tinkerpop.com) has nothing to do with graphs. Gremlin (http://gremlin.tinkerpop.com) adds "graph pipes" to Pipes. As such, Pipes is a general purpose dataflow framework.

> Code composed from examples:
> IndexableGraph g = TinkerGraphFactory.createTinkerGraph();
> GremlinPipeline pipe = new GremlinPipeline(g.getVertex(1)).out("knows");
> System.out.println("Vertex Count: " + pipe.count());
>
> This works fine, I used GremlinPipeline, becuase that's what I saw in the example.
> How do I go about printing the names in output as:
>
> Marko knows: (hopefully both values from the graph and not hardcoded, so that later I can also try all outer edges)
> Name: Josh, 32
> Name: Vadas, 27

Do this:

List results = new GremlinPipeline(g.getVertex(1)).out("knows").property("name").toList()
System.out.println(results) // non-lazy evaluation model

-or-

for(String name : new GremlinPipeline<Vertex,String>(g.getVertex(1)).out("knows").property("name")) {
System.out.println(name); // lazy evaluation model
}

You might have to fuggle with typing, but that is the basic idea.

HTH,
Marko.

http://markorodriguez.com

pShah

unread,
May 4, 2012, 3:12:48 PM5/4/12
to gremli...@googlegroups.com
Hi Marko,
  Thanks for the quick response.  I tried your code and made some changes as you suggested.  However I have a followup question:

  Updated Print code:
        List results;
       
        System.out.println("Output 2:");

        results = new GremlinPipeline(g.getVertex(1)).out("knows")
                .property("name").toList();
        System.out.println(results); // non-lazy evaluation model

        System.out.println("Output 3:");
        for (Object name : new GremlinPipeline<Vertex, String>(g.getVertex(1))

                .out("knows").property("name")) {
            System.out.println(name); // lazy evaluation model
        }

  Followup Question:
  Based on my previous question where I already have the GremlinPipeline constructed, why does the following not work?
        List results;

        IndexableGraph g = TinkerGraphFactory.createTinkerGraph();
        GremlinPipeline pipe = new GremlinPipeline(g.getVertex(1)).out("knows")
                .property("name");

        System.out.println("Vertex Count: " + pipe.count());

        // Not working
        System.out.println("Output 1:");
        results = pipe.toList();
        System.out.println(results);


  Output is:
  Output 1:
  []


 
Thanks for all your efforts

Marko Rodriguez

unread,
May 4, 2012, 3:47:02 PM5/4/12
to gremli...@googlegroups.com
Hi,

        // Not working
        System.out.println("Output 1:");
        results = pipe.toList();
        System.out.println(results);


  Output is:
  Output 1:
  []

Because you already iterated your pipeline. While Pipe implements Iterable/Iterator, note the JavaDoc, Iterable is not faithful to Java's intention and only used for the benefit of foreach. I plan to make Iterable be faithful, just haven't gotten around to it or thought about how difficult it would be.........

Marko.

pShah

unread,
May 4, 2012, 4:00:37 PM5/4/12
to gremli...@googlegroups.com
Thanks for the explanation.  As long as I know that it is not possible right now I will just put the entire GremlinPipeLine in the foreach as you showed earlier.

Thanks
Reply all
Reply to author
Forward
0 new messages