I use the following code to create an edge
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());
This prints edgeId as 1lb-394-36d-38
. As a result of this, I am getting NumberFormatException. I thought all ids are long by default. Is there something I need to configure?
This is my current configuration
gremlin.graph=org.janusgraph.core.JanusGraphFactory
storage.backend=berkeleyje
storage.directory=jgex/berkeleyje
index.jgex.backend=lucene
index.jgex.directory=jgex/lucene
I tried the same on gremlin console, I am getting a long ID as expected, irrespective of how many times I execute. I did this to see if coalesce
is causing some issue
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
gremlin> g.V(0L).as("fromVertex").V(2L).coalesce(inE("MIXES_WITH").where(outV().as("fromVertex")), addE("MIXES_WITH").from("fromVertex")).next().id()
==>6
Edge IDs in JanusGraph are stored using a special class called RelationIdentifier that contains a lot more information than just the ID itself. The ID of that class is a "UUID like" identifier. You can get other information from the class. Below is an example using a simple 'inmemory' JanusGraph from the Gremlin Console.
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