如何在 Gremlin PipeLine 中使用 "AND" 条件
How to use "AND" condition in GremlinPipeLine
假设我有一个顶点列表 Person 具有属性 name 和 age.I想编写一个查询,以生成具有 name="John" and age=22
的顶点。
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)
我认为这里没有必要使用 and
步骤。只需管道两个 has
条件:
g.V.has('name','John').has('age',22)
这实际上是一个 AND 运算。在 Java 中,我猜这将是:
new GremlinPipeline(graph).V().has("name", "John").has("age",22);
请阅读 如何从 groovy 转换为 java 以获取有关该主题的更多信息。
假设我有一个顶点列表 Person 具有属性 name 和 age.I想编写一个查询,以生成具有 name="John" and age=22
的顶点。
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)
我认为这里没有必要使用 and
步骤。只需管道两个 has
条件:
g.V.has('name','John').has('age',22)
这实际上是一个 AND 运算。在 Java 中,我猜这将是:
new GremlinPipeline(graph).V().has("name", "John").has("age",22);
请阅读