0

Here is the sample code which I am using but I don't know how to use this Pipeline object to get the vertices & it's properties.

GremlinPipeline pipeline = new GremlinPipeline(vert)
  .out("LIVES_IN_CITY").in("LIVES_IN_CITY")
  .filter(new PipeFunction<Vertex,Boolean>() {
            public Boolean compute(Vertex v){
                  return v.getProperty("name").equals(city);     
  }}).back(2).out("LIVES_IN_CITY");
stephen mallette
  • 45,298
  • 5
  • 67
  • 135
RCS
  • 1,370
  • 11
  • 27
  • I don't really follow what you are asking. Could you please reform your question? Are you asking how to get a "result" from the pipeline you have shown in your sample code? – stephen mallette Mar 07 '15 at 12:23
  • vert is the employee node which is start node & LIVES_IN_CITY is the edge from employee node towards city node. I want to find out who are other employee lives in the same city. gremline query could be : g.V.('id',1234).out('LIVES_IN_CITY').inE.outV TO get the above result, i am using gremlinepipeline java api but i am not able to iterate properly & get the result. Please suggest me how to achieve the above result. – RCS Mar 08 '15 at 17:51

1 Answers1

1

A Gremlin Pipeline is just an Iterator - so treat it as such. At a low level, use a while loop to iterate checking hasNext() to see if there are more items in the pipeline to extract and use next to pop off the very next item in the Iterator.

Pipeline also has toList() and fill() methods to work at a higher level of abstraction. You can see the API here.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • I tried to iterate but getting classcast exception : java.lang.ClassCastException: com.thinkaurelius.titan.graphdb.vertices.CacheVertex cannot be cast to com.tinkerpop.blueprints.Edge – RCS Mar 09 '15 at 15:06
  • Are you executing the same pipeline code you have in your question? i'm not seeing how you get that exception given that block of code. – stephen mallette Mar 09 '15 at 17:09
  • For above block of code, i am getting - com.tinkerpop.pipes.util.FastNoSuchElementException. I have made some changes in the above code mentioned below & got the ClassCastException which i have mentioned in my 1st comment. GremlinPipeline pipe1 = new GremlinPipeline(vert).out("LIVES_IN_CITY").as("x").inV().filter(new PipeFunction() { public Boolean compute(Vertex v){ System.out.println("pass ho rha hai"); return v.getProperty("name").equals("HOUSTON"); } }).back(2).out("LIVES_IN_CITY"); – RCS Mar 10 '15 at 05:54
  • If you have a `FastNoSuchElementException` then there is no data in your pipeline, which might mean in your case that you have a bug in your traversal or your test data is incomplete. As for the `ClassCastException`, you are doing an `inV` from the `out('LIVES_IN_CITY')` step. Since `out` returns a `Vertex`, you can try to do an `inV` on it as that is a step for an `Edge`. – stephen mallette Mar 10 '15 at 11:44