Adding vertex with traversal in DSE Graph

9 views
Skip to first unread message

gw

unread,
Mar 15, 2018, 9:36:53 AM3/15/18
to DataStax Java Driver for Apache Cassandra User Mailing List
I am attempting to add a new Vertex and associate it with existing Vertex using traversal.  This method is not throwing any exceptions but the new Vertex is not created as a result.  Here is my code:


PassportTraversal<Vertex, Vertex> user_traversal = ... // get the user

user_traversal
   
.as("user")
   
.addV("account")
   
.as("account")
   
.property("accountI"D", accountId)
    .addE(has_account"
)
   
.from("user")
   
.select("account")
   
.setProperties(newAccount)
    .iterate();

I've seen examples of adding vertices using graph but not with traversal.  Am I missing something here?

Cheers,
~gw

Kevin Gallardo

unread,
Mar 15, 2018, 11:57:46 AM3/15/18
to java-dri...@lists.datastax.com
Hi George,

Are you sure the `user_traversal` traversal returns a vertex that exists? Could you show this traversal too please, as well as how you define "g"?

The usual semantics for adding vertices is, as recommended by TinkerPop:

g.
addV("....").property(...., ...).property(...., ...).as("fromV").
addV("....").property(...., ...).property(...., ...).as("toV").
addE("....").property(...., ...).
from("fromV").to("toV").
next(); // or iterate()

That should work, assuming "g" is a traversal source connected to DseGraph, via the `DseGraph.traversal(DseSession)`.

If one or both vertices already exist you can replace the `addV()` part with a traversal that gathers the vertex, such as `V().has(...., ...).as("from/toV")` and so on.

Please try this syntax and let us know how it goes.
Thanks.

--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-user+unsubscribe@lists.datastax.com.



--
Kévin Gallardo.
Software Developer in Drivers and Tools Team,
DataStax.

gw

unread,
Mar 16, 2018, 10:56:54 AM3/16/18
to DataStax Java Driver for Apache Cassandra User Mailing List

Thanks, Kevin.  Your recommendation worked for me.
I am defining "g" as g = DseGraph.traversal(graphSession, MyTraversalSource.class) where MyTraversalSource extends GraphTraversalSource


Reply all
Reply to author
Forward
0 new messages