在 Janusgraph 中,edgeID 以字母数字而不是 long 形式返回

问题描述

我使用下面的代码来创建一个

        Edge e = this.g
            .V(fromId) // get vertex of id given for the source
            .as("fromVertex") // label as fromVertex to be accessed later
            .V(toId) // get  vertex of id given for destination
            .coalesce( // evaluates the provided traversals in order and returns the first traversal that emits at least one element
                inE(label) // check incoming edge of label given
                    .where( // conditional check to check if edge exists
                        outV() // get destination vertex of the edge to check
                            .as("fromVertex")),// against staged vertex
                addE(label) // add edge if not present
                    .from("fromVertex"))
            .next(); // end traversal to commit to graph

        System.out.println(Long.parseLong(e.id().toString());

这会将 edgeId 打印为 1lb-394-36d-38。因此,我收到了 NumberFormatException。我认为认情况下所有 id 都很长。有什么我需要配置的吗?

这是我当前的配置

gremlin.graph=org.janusgraph.core.JanusGraphFactory

storage.backend=berkeleyje
storage.directory=jgex/berkeleyje

index.jgex.backend=lucene
index.jgex.directory=jgex/lucene

我在 gremlin 控制台上尝试了相同的操作,无论执行多少次,我都按预期获得了很长的 ID。我这样做是为了查看 coalesce 是否导致了一些问题

gremlin> g.V(0L).as("fromVertex").V(2L).coalesce(inE("MIXES_WITH").where(outV().as("fromVertex")),addE("MIXES_WITH").from("fromVertex")).next().id()
==>6

gremlin> g.V(0L).as("fromVertex").V(2L).coalesce(inE("MIXES_WITH").where(outV().as("fromVertex")),addE("MIXES_WITH").from("fromVertex")).next().id()
==>6

解决方法

JanusGraph 中的边 ID 使用称为 RelationIdentifier 的特殊类进行存储,该类包含比 ID 本身更多的信息。该类的 ID 是“类似 UUID”的标识符。您可以从班级中获取其他信息。下面是一个使用来自 Gremlin 控制台的简单“inmemory”JanusGraph 的示例。

gremlin> g.addV('a').as('a').addV('b').as('b').addE('test').from('a').to('b')
==>e[16p-360-2dx-9jk][4104-test->12368]

gremlin> g.V().hasLabel('a').outE().next().class
==>class org.janusgraph.graphdb.relations.StandardEdge

gremlin> g.V().hasLabel('a').outE().id().next().class
==>class org.janusgraph.graphdb.relations.RelationIdentifier

gremlin> g.V().hasLabel('a').outE().id().next().class.methods
==>public long org.janusgraph.graphdb.relations.RelationIdentifier.getTypeId()
==>public long org.janusgraph.graphdb.relations.RelationIdentifier.getOutVertexId()
==>public long org.janusgraph.graphdb.relations.RelationIdentifier.getInVertexId()
==>public long[] org.janusgraph.graphdb.relations.RelationIdentifier.getLongRepresentation()
==>public long org.janusgraph.graphdb.relations.RelationIdentifier.getRelationId()
==>public static org.janusgraph.graphdb.relations.RelationIdentifier org.janusgraph.graphdb.relations.RelationIdentifier.get(int[])
==>public static org.janusgraph.graphdb.relations.RelationIdentifier org.janusgraph.graphdb.relations.RelationIdentifier.get(long[])
==>public boolean org.janusgraph.graphdb.relations.RelationIdentifier.equals(java.lang.Object)
==>public java.lang.String org.janusgraph.graphdb.relations.RelationIdentifier.toString()
==>public int org.janusgraph.graphdb.relations.RelationIdentifier.hashCode()
==>public static org.janusgraph.graphdb.relations.RelationIdentifier org.janusgraph.graphdb.relations.RelationIdentifier.parse(java.lang.String)
==>public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
==>public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
==>public final void java.lang.Object.wait() throws java.lang.InterruptedException
==>public final native java.lang.Class java.lang.Object.getClass()
==>public final native void java.lang.Object.notify()
==>public final native void java.lang.Object.notifyAll()

gremlin> g.V().hasLabel('a').outE().id().next().getRelationId()   
==>1537