2015-05-19 47 views
0

假設有頂點使用屬性年齡。我想編寫一個查詢導致具有name="John" and age=22頂點的列表。我如何使用「AND」條件GremlinPipeLine

Pipe pipe = (Pipe) new GremlinPipeline(graph).V().has("name", "John"); 
Pipe pipe2=new GremlinPipeline(graph).V().has("age", "22"); 
List<Vertex> verList = (List<Vertex>) new GremlinPipeline(graph).V().and(pipe,pipe2).toList(); 

我不知道這是否是實現it.It拋出下面的異常

Exception in thread "main" java.lang.ClassCastException: com.thinkaurelius.titan.graphdb.vertices.CacheVertex cannot be cast to com.tinkerpop.blueprints.Graph 
at com.tinkerpop.pipes.transform.GraphQueryPipe.processNextStart(GraphQueryPipe.java:33) 
at com.tinkerpop.pipes.transform.GraphQueryPipe.processNextStart(GraphQueryPipe.java:17) 
at com.tinkerpop.pipes.AbstractPipe.next(AbstractPipe.java:89) 
at com.tinkerpop.pipes.IdentityPipe.processNextStart(IdentityPipe.java:19) 
at com.tinkerpop.pipes.AbstractPipe.hasNext(AbstractPipe.java:98) 
at com.tinkerpop.pipes.util.Pipeline.hasNext(Pipeline.java:105) 
at com.tinkerpop.pipes.transform.HasNextPipe.processNextStart(HasNextPipe.java:36) 
at com.tinkerpop.pipes.transform.HasNextPipe.processNextStart(HasNextPipe.java:16) 
at com.tinkerpop.pipes.AbstractPipe.next(AbstractPipe.java:89) 
at com.tinkerpop.pipes.filter.AndFilterPipe.processNextStart(AndFilterPipe.java:35) 
at com.tinkerpop.pipes.AbstractPipe.next(AbstractPipe.java:89) 
at com.tinkerpop.pipes.util.Pipeline.next(Pipeline.java:115) 
at com.tinkerpop.pipes.util.PipeHelper.fillCollection(PipeHelper.java:52) 
at com.tinkerpop.gremlin.java.GremlinPipeline.toList(GremlinPipeline.java:1564) 
at BulkLoad_New.search(BulkLoad_New.java:320) 
at BulkLoad_New.main(BulkLoad_New.java:71) 

回答

1

我不認爲有太大的必要使用and一步這裏的正確途徑。只需管道has條件:

g.V.has('name','John').has('age',22) 

這實際上是一種AND操作。在Java中我想這會是:

new GremlinPipeline(graph).V().has("name", "John").has("age",22); 

請閱讀關於如何從常規到Java轉換爲有關該主題的更多信息this post

+0

在哪種情況下我們確切地使用'和'? @stephen – user2420143

+0

對於更復雜的情況,您可能會從當前評估的元素中移除,例如:'gVand(_()。outE('knows'),_()。out('likes')。has('type 」, '玩具'))' –