目标:我试图在单个遍历中添加一堆顶点和边,并返回其中的一部分。
可能是流畅的API仍然处于测试阶段,或者我还没有正确理解API:
我认为.select()和GraphResultSet one()和all()存在问题,但这是我尝试过的:
GraphTraversal<Vertex,Vertex> traversal = g.addV("Entity").property("uuid","testuuid").as("a")
.addV("Entity").property("uuid","testuuid3").as("b");
GraphStatement graphStatement = DseGraph.statementFromTraversal(traversal.select("a","b"));
GraphResultSet grs = dseSession.executeGraph(graphStatement.setGraphName("graph"));
我正在创建两个顶点a,b和我选择它们两个..如果我只选择一个
grs.one().as(Vector.class)
工作正常......但是现在我选择a和b ... grs.one()和grs.all()返回list []和obj {} .. iterator中的结果()因grs.all()。count()为1而无法正常工作。所以我无法得到我需要的东西..假设grs.all()返回两个东西和grs.one的迭代器( )返回第一件事。
grs.all()返回类似的内容:
[{a=DefaultVertex{id={~label=Entity, community_id=903802240, member_id=515}, label=Entity, properties=com.google.common.collect.Iterators$3@3670f00}, b=DefaultVertex{id={~label=Entity, community_id=903802240, member_id=516}, label=Entity, properties=com.google.common.collect.Iterators$3@452e26d0}}]
grs.one()返回类似的内容:
{a=DefaultVertex{id={~label=Entity, community_id=1220980480, member_id=514}, label=Entity, properties=com.google.common.collect.Iterators$3@10b892d5}, b=DefaultVertex{id={~label=Entity, community_id=1220980480, member_id=515}, label=Entity, properties=com.google.common.collect.Iterators$3@3d3f761a}}
编辑(尝试迭代同一行中的多个内容(请参阅评论):
GraphNode ga = grs.all().iterator().next(); // this contains both a and b
System.out.println(ga.getClass()); // this is ObjectGraphNode :/
我正在使用:
<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>
感谢任何帮助!
答案 0 :(得分:2)
我不确定您的期望是什么,但select("a","b")
应该在单个“行”中返回两个顶点。 all()
和one()
的结果对我来说都很好。
这是一个疯狂的猜测;你可能正在寻找这样的东西:
g.addV("Entity").property("uuid","testuuid").union(identity(),
addV("Entity").property("uuid","testuuid3"))
此遍历将创建2个顶点并将它们返回到2个单独的行中。
<强>更新强>
在下面的评论中找出用例是迭代GraphNode
中返回的映射条目(这是DSE Graph API返回的任何对象的包装),答案是:应该是以下之一。
如果您只需要第一个顶点:
executeGraph(statementFromTraversal(
g.addV("Entity").property("uuid","testuuid").sideEffect(
addV("Entity").property("uuid","testuuid3"))).one().asVertex()
如果您只需要第二个顶点:
executeGraph(statementFromTraversal(
g.addV("Entity").property("uuid","testuuid").
addV("Entity").property("uuid","testuuid3")).one().asVertex()
如果您需要所有/多个顶点:
GraphNode n = executeGraph(statementFromTraversal(
g.addV("Entity").property("uuid","testuuid").as("a").
addV("Entity").property("uuid","testuuid3").as("b").select("a","b")).one()
n.get("a").asVertex() // work w/ vertex a
n.get("b").asVertex() // work w/ vertex b