Hello team,
I am trying out a new graph implementation using the Tinkerpop stack. I have implemented all structure elements and underlying persistent store interactions. For example I have a CustomVertex implementing the Vertex, CustomGraph implementing Graph etc.. The graph is working fine and gremlin queries are executed as expected.
Now I need to run Groovy Script against this custom Graph implementation. Can anyone please suggest the best method for that.
I tried the below methods, which is not working properly. The Tinkerpop pipe implementations internally trying to cast the vertices into blueprint vertex versions and is failing there. Please find below the code and the exception stack trace.
CustomGraph graph = (CustomGraph) GraphFactory.open(cfg);
Pipe pipe = Gremlin.compile("_().out('customLabel').property");
pipe.setStarts(new SingleIterator<Vertex>(graph.vertex("1")));
while (pipe.hasNext()) {
pipe.next();
}
Exception in thread "main" java.lang.ClassCastException: com.nirmal.structure.CustomVertex cannot be cast to com.tinkerpop.blueprints.Vertex
at com.tinkerpop.pipes.transform.VertexQueryPipe.processNextStart(VertexQueryPipe.java:85)
at com.tinkerpop.pipes.transform.VertexQueryPipe.processNextStart(VertexQueryPipe.java:19)
at com.tinkerpop.pipes.AbstractPipe.next(AbstractPipe.java:89)
at com.tinkerpop.pipes.transform.PropertyPipe.processNextStart(PropertyPipe.java:29)
at com.tinkerpop.pipes.AbstractPipe.hasNext(AbstractPipe.java:98)
at com.tinkerpop.pipes.util.Pipeline.hasNext(Pipeline.java:105)
at com.nirmal.GraphFramework.main(GraphFramework.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
I have also tried using Groovy classes, which also throws an exception trying to cast to Blueprints versions.
Please find below the Groovy class.
class GraphAlgorithms {
static {
Gremlin.load()
}
public static Map<Vertex, Integer> eigenvectorRank(Graph g) {
Map<Vertex,Integer> m = [:]; int c = 0
g._().has("label", "customLabel").as('x').out.groupCount(m).loop('x') {c++ < 1000}.iterate()
return m
}
}
Below given is the Java Code
CustomGraph graph = (CustomGraph) GraphFactory.open(cfg);
GraphAlgorithms.eigenvectorRank(graph);
Please find below the exception.
Exception in thread "main" java.lang.ClassCastException: com.nirmal.structure.CustomGraph cannot be cast to com.tinkerpop.blueprints.Edge
at com.tinkerpop.pipes.filter.LabelFilterPipe.processNextStart(LabelFilterPipe.java:25)
at com.tinkerpop.pipes.filter.LabelFilterPipe.processNextStart(LabelFilterPipe.java:13)
at com.tinkerpop.pipes.AbstractPipe.next(AbstractPipe.java:89)
at com.tinkerpop.pipes.util.AsPipe.processNextStart(AsPipe.java:42)
at com.tinkerpop.pipes.AbstractPipe.hasNext(AbstractPipe.java:98)
at com.tinkerpop.pipes.branch.LoopPipe$ExpandableLoopBundleIterator.next(LoopPipe.java:143)
at com.tinkerpop.pipes.util.iterators.HistoryIterator.next(HistoryIterator.java:25)
at com.tinkerpop.pipes.transform.VertexQueryPipe.processNextStart(VertexQueryPipe.java:85)
at com.tinkerpop.pipes.transform.VertexQueryPipe.processNextStart(VertexQueryPipe.java:19)
at com.tinkerpop.pipes.AbstractPipe.next(AbstractPipe.java:89)
at com.tinkerpop.pipes.sideeffect.GroupCountPipe.processNextStart(GroupCountPipe.java:28)
at com.tinkerpop.pipes.AbstractPipe.next(AbstractPipe.java:89)
at com.tinkerpop.pipes.util.Pipeline.next(Pipeline.java:115)
at com.tinkerpop.pipes.branch.LoopPipe.processNextStart(LoopPipe.java:44)
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.iterate(PipeHelper.java:35)
at com.tinkerpop.gremlin.java.GremlinPipeline.iterate(GremlinPipeline.java:1542)
at com.tinkerpop.gremlin.java.GremlinFluentPipeline$iterate.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at com.nirmal.GraphAlgorithms.eigenvectorRank(GraphAlgorithms.groovy:17)
at com.nirmal.GraphFramework.main(GraphFramework.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
I am not sure if I have missed anything here. Could you please check if this is and see if any enhancements are required for Tinkerpop implementations here.
Thanks,
Nirmal J