Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Not A Problem
-
3.3.3
-
None
-
None
Description
Attempts to add edges during a vertex program on tinkergraph result in a ClassCastException because org.apache.tinkerpop.gremlin.process.computer.util.ComputerGraph.ComputerVertex can't be cast to class org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex.
In a vertex program designed to add edges to the graph based on rules, attempts to call vertex.addEdge(label,otherVertex,edgeProperties) can only result in a ClassCastException on Tinkergraph. At runtime, the Vertex argument to VertexProgram.execute(vertex,messenger,memory) has class org.apache.tinkerpop.gremlin.process.computer.util.ComputerGraph.ComputerVertex. Both the vertex and the otherVertex are instances of class ComputerGraph.ComputerVertex, but when addEdge is called on the ComputerGraph.ComputerVertex instance, internally it calls the addEdge(...) of the wrapped TinkerVertex. TinkerVertex.addEdge(...) casts the otherEdge to a TinkerVertex, which it is not. There is no way to get an instance of a TinkerVertex in a VertexProgram without specifically handling this case, casting to ComputerGraph.ComputerVertex or WrappedVertex, and getting the wrapped vertex of the other vertex before calling addEdge. This is not portable across backends!
A fix might be to add handling for instances of ComputerGraph.ComputerVertex or <C extends WrappedVertex> and get the base vertex before casting to TinkerVertex.
EDIT: Workaround exists, downgrade to minor. Added test for WrappedVertex.class in my vertex program and performed a getBaseVertex() call on the target vertex before calling addEdge.
if(WrappedVertex.class.isAssignableFrom(mate.getClass()))
{ vertex.addEdge("similarTo", ((WrappedVertex<Vertex>)mate).getBaseVertex(), edgeProperties); }else
{ vertex.addEdge("similarTo", mate, edgeProperties); }