如何以tinkerpop / gremlin格式而不是DSE图格式返回Vertex? [英] How to return a Vertex in the tinkerpop/gremlin format instead of the DSE graph format?
问题描述
我正在尝试返回它刚刚用Gremlin创建的Vertex(以tinkerpop格式):
I am trying to return a Vertex (in tinkerpop format) that it was just created with Gremlin:
DseCluster dseCluster = DseCluster.builder()
.addContactPoint(DbC.dseHost)
.build();
DseSession dseSession = dseCluster.connect();
GraphTraversal traversal = graph.addV(VertexLabels.User)
.property("username", "testuser")
GraphStatement graphStatement = DseGraph.statementFromTraversal(
traversal
);
GraphResultSet grs = dseSession.executeGraph(graphStatement.setGraphName(DbC.graphName));
Vertex v = grs.one().as(Vertex.class);
我得到了这个例外......
and I am getting this exception...
java.lang.ClassCastException:com.datastax.driver.dse.graph.DefaultVertex无法强制转换为org.apache.tinkerpop.gremlin.structure.Vertex
如何更改代码以便以gremlin.structure.Vertex格式而不是DSE Graph Vertex格式返回?
How could the code be changed so that it returns in gremlin.structure.Vertex format instead of the DSE Graph Vertex format?
我正在使用:
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>dse-driver</artifactId>
<version>1.1.1-beta1</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>java-dse-graph</artifactId>
<version>1.0.0-beta1</version>
</dependency>
我希望可以这样做,否则从TitanDB迁移会很痛苦..
I hope this can be done otherwise migration from TitanDB will be painful..
推荐答案
根据我与Datastax团队通过 jira 和电子邮件:
According to the lengthy discussion I had with Datastax Team through jira and emails:
确实可以使用Fluent API并获得纯Gremlin / tinkerpop对象。这可以如此处所示( java -dse graph 1.x文档)直接在GraphTraversalSource上使用next(),toList()而不使用将返回DSE对象的executeGraph()。
It is indeed possible to have Fluent API and get back pure Gremlin/tinkerpop objects. This is possible as illustrated here (java-dse graph 1.x documentation) using next(), toList() directly on GraphTraversalSource and not using executeGraph() which will return the DSE Objects.
所以上面的代码更改为:
So the above code changes to:
Vertex user = graph.addV("User")
.property("username", "testuser").next();
其中 graph
是 GraphTraversalSource< Vertex,Vertex>
object和 Vertex
是一个 org.apache.tinkerpop.gremlin.structure.Vertex
object。
where graph
is a GraphTraversalSource<Vertex,Vertex>
object and Vertex
is a org.apache.tinkerpop.gremlin.structure.Vertex
object.
这篇关于如何以tinkerpop / gremlin格式而不是DSE图格式返回Vertex?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!