Creating vertex with many properties

6 views
Skip to first unread message

Homesh Rawat

unread,
May 10, 2018, 5:05:01 AM5/10/18
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi ,
I need to create a vertex with different properties and each property may have a different data type. 
I checked tinkerpop's documentation and I could see that to add properties, we can pass only two methods key and value in the property method.
g.addV('person').property('name','stephen')

However, in my use case I want to add multiple properties with different datatype at once. As of now I am looping on the key array and for every key executing the statement. But I don't believe this is the optimum way to do this.

GraphStatement statement;

GraphResultSet grs;
for (int i=0; i<keys.size(); i++) {

    statement = DseGraph.statementFromTraversal(g.V().has("name","homesh").property(keys.get(i), values.get(i)));                                    
         grs = session.executeGraph(statement);

}


Can you please suggest me what is the better way to do this.

--
Homesh

Kevin Gallardo

unread,
May 10, 2018, 11:15:46 AM5/10/18
to java-dri...@lists.datastax.com
Hi Homesh, 


.property() calls can be chained.

Example:

g.addV("person").property("id", UUID.randomUUID()).property("name", "marko").property("age", 29)

Not sure I understood your example right but in a loop, you can re-assign a traversal and add a property() step for each of the keys you have:

List keys = ...;
List values = ...;

GraphTraversal mutation = DseGraph.traversal().addV("person");
for (int i = ; i < keys.size(); i++) {
    mutation = mutation.property(keys.get(i), values.get(i));
}

dseSession.executeGraph(statementFromTraversal(mutation));

There is no step in TinkerPop as far as I can see in the docs that allows to add more than one property at a time.

Hope that helps.

On Thu, May 10, 2018 at 5:05 AM, Homesh Rawat <homes...@gmail.com> wrote:
Hi ,
I need to create a vertex with different properties and each property may have a different data type. 
I checked tinkerpop's documentation and I could see that to add properties, we can pass only two methods key and value in the property method.
g.addV('person').property('name','stephen')

However, in my use case I want to add multiple properties with different datatype at once. As of now I am looping on the key array and for every key executing the statement. But I don't believe this is the optimum way to do this.

GraphStatement statement;

GraphResultSet grs;
for (int i=; i<keys.size(); i++) {

    statement = DseGraph.statementFromTraversal(g.V().has("name","homesh").property(keys.get(i), values.get(i)));                                    
         grs = session.executeGraph(statement);

}


Can you please suggest me what is the better way to do this.

--
Homesh

--
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 Engineer in Developers Tools Team,
DataStax.

Reply all
Reply to author
Forward
0 new messages