簡體   English   中英

帶有框架的Gremlin Groovy ClassCastException

[英]Gremlin Groovy ClassCastException with 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)
    ....

以下行導致錯誤:

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

哪個正在調用此方法:

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

我還嘗試了以下遍歷(導致相同的錯誤):

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

但是,當我打開gremlin外殼來測試相同的遍歷時-一切正常。 有什么想法可能導致此問題?

這並不是解決方案的答案。 除了使用@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();
    }
}

我認為您在這里沒有適當的用法,可以在Frames上為該注釋提供文檔:

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

首先,請注意:

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

和:

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

返回一個Iterator所以它不是getFooEdgeFromUuid()用,因為您不需要在getFooEdgeFromUuid()返回某種形式的List 假設您知道此查詢將僅且始終返回一條邊的事實,那么可能要做的事情是:

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

我之所以說“總是”,是因為否則,您將獲得NoSuchElementException 這樣,可以正確對齊類型,您可以執行以下操作:

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

當然,所有這些可能都不起作用,因為我在文檔中看到了這句話:

可以使用Gremlin路徑表達式作為通過GremlinGroovyModule確定頂點鄰接的方法。

換句話說,使用@GremlinGroovy可以返回框架頂點(而不是您嘗試做的邊)。 如果我上面建議的方法不起作用,那么使用@JavaHandler的解決方法可能是您的最佳選擇。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM