JanusGraph vertex.edges() returns 一个 RelationConstructor 而不是一个 Iterator<Edge>

JanusGraph vertex.edges() returns a RelationConstructor rather an Iterator<Edge>

我正在 JVM 上尝试基本的 JanusGraph 操作。

当我试图简单地在两个顶点之间创建一条边并调用 vertex1.edges() 时,我得到的结果是 org.janusgraph.graphdb.transaction.RelationConstructor 而不是 Iterator<Edge>,这与 api 相悖.

我可以在 Gremlin 控制台上重新生成一次相同的结果,如下所示。但我在随后的尝试中得到了正确的org.janusgraph.graphdb.query.ResultSetIterator

gremlin> person = graph.addVertex(label, 'person')
==>v[163844144]
gremlin> graph.tx().commit()
==>null
gremlin> person2 = graph.addVertex(label, 'anotherperson')
==>v[245764240]
gremlin> person.addEdge("knows", person2);
==>e[2pjoxy-2pjqy8-29ed-42bkwg][163844144-knows->245764240]
gremlin> graph.tx().commit()
==>null
gremlin> person.class
==>class org.janusgraph.graphdb.vertices.StandardVertex
gremlin> mye = person.edges(Direction.BOTH, "knows")
==>e[2pjoxy-2pjqy8-29ed-42bkwg][163844144-knows->245764240]
gremlin> mye.class
==>class org.janusgraph.graphdb.transaction.RelationConstructor

有人可以解释为什么 and/or 建议解决方法吗? 谢谢!

你回来了class org.janusgraph.graphdb.transaction.RelationConstructor。注意 </code>,它表示您正在处理 <code>RelationConstructor 中的匿名 class。特别是,您将从方法 readRelation() 中取回此 Iterator。可以肯定的是,您可以在会话中调用 mye instanceof Iterator 来验证。

在下面的这个例子中,我在 mye 分配的末尾添加了 null 以防止 Gremlin 控制台 auto-iteration 行为。

gremlin> mye = person.edges(Direction.BOTH, "knows"); null
==>null
gremlin> mye instanceof Iterator
==>true
gremlin> myedge = (mye.hasNext()) ? mye.next() : null
==>e[2pjoxy-2pjqy8-29ed-42bkwg][163844144-knows->245764240]
gremlin> myedge.class
==>class org.janusgraph.graphdb.relations.CacheEdge