how to return specific vertex in traversal that is creating two vertices connected by edge (DSE 5.0 Graph)

91 views Asked by At

I have a traversal that I create two vertices and I connect them with an edge like that:

    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 

How can I make the resultset contain only a specific vertex like "a" source vertex for example?

I know I could do instead:

GraphTraversal traversal = g
    .addV("aLabel").as("a")
    .addV("aLabel").as("b")
    .addE("edgeLabel").from("a").to("b").outV() // this returns a 

but I am looking in a solution like

 GraphTraversal traversal = g
    .addV("aLabel").as("a")
    .addV("aLabel").as("b")
    .addE("edgeLabel").from("a").to("b").emit("a") // this doesn't work

Thanks!

1

There are 1 answers

0
Michail Michailidis On BEST ANSWER

The answer that worked is using select:

GraphTraversal<Vertex,Vertex> traversal = g
    .addV("aLabel").as("a")
    .addV("aLabel").as("b")
    .addE("edgeLabel").from("a").to("b").select("a")

or

Vertex v =  g
        .addV("aLabel").as("a")
        .addV("aLabel").as("b")
        .addE("edgeLabel").from("a").to("b").<Vertex>select("a").next();