如何 return 遍历中创建由边连接的两个顶点的特定顶点(DSE 5.0 Graph)
how to return specific vertex in traversal that is creating two vertices connected by edge (DSE 5.0 Graph)
我有一个遍历,我创建了两个顶点并将它们与一条边连接起来:
DseCluster dseCluster = null;
dseCluster = DseCluster.builder()
.addContactPoint(DbC.dseHost)
.build();
DseSession dseSession = dseCluster.connect();
GraphTraversalSource g = DseGraph.traversal(dseSession, new GraphOptions().setGraphName(DbC.graphName));
GraphTraversal traversal = g
.addV("aLabel").as("a")
.addV("aLabel").as("b")
.addE("edgeLabel").from("a").to("b")
GraphStatement graphStatement = DseGraph.statementFromTraversal(traversal);
GraphResultSet grs = dseSession.executeGraph(graphStatement.setGraphName(DbC.graphName));
//grs contains an edge only
如何使结果集仅包含特定顶点,例如 "a" 源顶点?
我知道我可以这样做:
GraphTraversal traversal = g
.addV("aLabel").as("a")
.addV("aLabel").as("b")
.addE("edgeLabel").from("a").to("b").outV() // this returns a
但我正在寻找类似
的解决方案
GraphTraversal traversal = g
.addV("aLabel").as("a")
.addV("aLabel").as("b")
.addE("edgeLabel").from("a").to("b").emit("a") // this doesn't work
谢谢!
有效的答案是使用 select:
GraphTraversal<Vertex,Vertex> traversal = g
.addV("aLabel").as("a")
.addV("aLabel").as("b")
.addE("edgeLabel").from("a").to("b").select("a")
或
Vertex v = g
.addV("aLabel").as("a")
.addV("aLabel").as("b")
.addE("edgeLabel").from("a").to("b").<Vertex>select("a").next();
我有一个遍历,我创建了两个顶点并将它们与一条边连接起来:
DseCluster dseCluster = null;
dseCluster = DseCluster.builder()
.addContactPoint(DbC.dseHost)
.build();
DseSession dseSession = dseCluster.connect();
GraphTraversalSource g = DseGraph.traversal(dseSession, new GraphOptions().setGraphName(DbC.graphName));
GraphTraversal traversal = g
.addV("aLabel").as("a")
.addV("aLabel").as("b")
.addE("edgeLabel").from("a").to("b")
GraphStatement graphStatement = DseGraph.statementFromTraversal(traversal);
GraphResultSet grs = dseSession.executeGraph(graphStatement.setGraphName(DbC.graphName));
//grs contains an edge only
如何使结果集仅包含特定顶点,例如 "a" 源顶点?
我知道我可以这样做:
GraphTraversal traversal = g
.addV("aLabel").as("a")
.addV("aLabel").as("b")
.addE("edgeLabel").from("a").to("b").outV() // this returns a
但我正在寻找类似
的解决方案 GraphTraversal traversal = g
.addV("aLabel").as("a")
.addV("aLabel").as("b")
.addE("edgeLabel").from("a").to("b").emit("a") // this doesn't work
谢谢!
有效的答案是使用 select:
GraphTraversal<Vertex,Vertex> traversal = g
.addV("aLabel").as("a")
.addV("aLabel").as("b")
.addE("edgeLabel").from("a").to("b").select("a")
或
Vertex v = g
.addV("aLabel").as("a")
.addV("aLabel").as("b")
.addE("edgeLabel").from("a").to("b").<Vertex>select("a").next();