简体   繁体   English

带有框架的Gremlin Groovy ClassCastException

[英]Gremlin Groovy ClassCastException with Frames

I'm receiving the following error while using the @GremlinGroovy annotation associated with tinkerpop's frames. 使用与tinkerpop的帧关联的@GremlinGroovy批注时,我收到以下错误。

java.lang.ClassCastException: com.thinkaurelius.titan.graphdb.relations.CacheEdge cannot be cast to com.tinkerpop.blueprints.Vertex
    at com.tinkerpop.frames.structures.FramedVertexIterable$1.next(FramedVertexIterable.java:36)
    at com.tinkerpop.frames.annotations.gremlin.GremlinGroovyAnnotationHandler.processVertex(GremlinGroovyAnnotationHandler.java:75)
    at com.tinkerpop.frames.annotations.gremlin.GremlinGroovyAnnotationHandler.processElement(GremlinGroovyAnnotationHandler.java:114)
    at com.tinkerpop.frames.annotations.gremlin.GremlinGroovyAnnotationHandler.processElement(GremlinGroovyAnnotationHandler.java:30)
    at com.tinkerpop.frames.FramedElement.invoke(FramedElement.java:83)
    at com.sun.proxy.$Proxy81.getProxyCandidateEdgeFromPersonUuid(Unknown Source)
    at com.company.prod.domain.Person$Impl.toImpl(Person.java:100)
    ....

The following line causes the error: 以下行导致错误:

FooEdge fe = foo.getFooEdgeFromUuid(this.getUuid());

Which is calling this method: 哪个正在调用此方法:

@GremlinGroovy("it.outE('has').filter{it.inV().has('uuid', T.eq, uuid).hasNext()}")
FooEdge getFooEdgeFromUuid(@GremlinParam("uuid") String uuid);

I've also tried the following traversal (which causes the same error): 我还尝试了以下遍历(导致相同的错误):

@GremlinGroovy("it.out('has').has('uuid', T.eq, uuid).inE('has')")

However, when I open a gremlin shell to test out the same exact traversal - everything works out just fine. 但是,当我打开gremlin外壳来测试相同的遍历时-一切正常。 Any thoughts on what may be causing the issue? 有什么想法可能导致此问题?

This isn't as much of an answer as it is to a workaround. 这并不是解决方案的答案。 Instead of using the @GremlinGroovy annotation one can use gremlin with the @JavaHandler annotation. 除了使用@GremlinGroovy批注之外,还可以将gremlin与@JavaHandler批注一起使用。

@JavaHandler
void getFooEdgeFromUuid(String uuid);

abstract class Impl implements JavaHandlerContext<Vertex>, Foo {
    public FooEdge getFooEdgeFromUuid(String uuid) {
        return frameEdges(
                gremlin().out("has")
                        .has("person-uuid", Tokens.T.eq, uuid)
                        .inE("has"),
                FooEdge.class).iterator().next();
    }
}

I don't think you have proper usage there give the documentation on Frames for that annotation: 我认为您在这里没有适当的用法,可以在Frames上为该注释提供文档:

https://github.com/tinkerpop/frames/wiki/Gremlin-Groovy https://github.com/tinkerpop/frames/wiki/Gremlin-Groovy

First, note that both: 首先,请注意:

@GremlinGroovy("it.outE('has').filter{it.inV().has('uuid', T.eq, uuid).hasNext()}")
FooEdge getFooEdgeFromUuid(@GremlinParam("uuid") String uuid);

and: 和:

@GremlinGroovy("it.out('has').has('uuid', T.eq, uuid).inE('has')")

returns an Iterator so that's not so helpful either as you would need to return some form of List in your getFooEdgeFromUuid() . 返回一个Iterator所以它不是getFooEdgeFromUuid()用,因为您不需要在getFooEdgeFromUuid()返回某种形式的List Perhaps the appropriate thing to do, assuming you know for a fact that this query will only and always return one edge would be to do: 假设您知道此查询将仅且始终返回一条边的事实,那么可能要做的事情是:

@GremlinGroovy("it.out('has').has('uuid', T.eq, uuid).inE('has').next()")

I say "always" because without that, you'll get yourself a NoSuchElementException otherwise. 我之所以说“总是”,是因为否则,您将获得NoSuchElementException In that way, to align types properly, you could do: 这样,可以正确对齐类型,您可以执行以下操作:

@GremlinGroovy("it.outE('has').filter{it.inV().has('uuid', T.eq, uuid)}")
Iterable<FooEdge> getFooEdgesFromUuid(@GremlinParam("uuid") String uuid);

Of course, all that may not work, because of this sentence I see in the docs: 当然,所有这些可能都不起作用,因为我在文档中看到了这句话:

It is possible to make use of a Gremlin path expression as a means of determining vertex adjacency via the GremlinGroovyModule. 可以使用Gremlin路径表达式作为通过GremlinGroovyModule确定顶点邻接的方法。

In other words, use of @GremlinGroovy is for returning framed vertices (and not edges as you are trying to do). 换句话说,使用@GremlinGroovy可以返回框架顶点(而不是您尝试做的边)。 If the approach I suggested above doesn't work then your workaround using the @JavaHandler may be your best option. 如果我上面建议的方法不起作用,那么使用@JavaHandler的解决方法可能是您的最佳选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM