Search code examples
datastax-enterprisedatastax-enterprise-graph

DSE graph modify vertex properties,


So its not obvious from the javadocs on how to modify properties of a Vertex after adding into graph.

I tried TinkerPop way.

GraphTraversalSource g = DseGraph.traversal(dseSession);
g.V().toStream().forEach(vertex -> vertex.property("name", "Santosh"));

But I get an exception

Exception in thread "main" java.lang.IllegalStateException: Property addition is not supported
    at org.apache.tinkerpop.gremlin.structure.Element$Exceptions.propertyAdditionNotSupported(Element.java:133)
    at org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex.property(DetachedVertex.java:91)
    at com.trimble.tpaas.profilex.random.MainGraphConnectivity.lambda$testSchemaCreation$0(MainGraphConnectivity.java:41)
    at org.apache.tinkerpop.gremlin.process.traversal.Traversal.forEachRemaining(Traversal.java:250)
    at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
    at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
    at com.trimble.tpaas.profilex.random.MainGraphConnectivity.testSchemaCreation(MainGraphConnectivity.java:41)
    at com.trimble.tpaas.profilex.random.MainGraphConnectivity.main(MainGraphConnectivity.java:23)

So question where can I refer to understand how to modify an existing vertex property using DSE java driver or otherwise.


Solution

  • When you connect to a DSE Graph with the DataStax Java Driver:

     g = DseGraph.traversal(dseSession)
    

    or the TinkerPop Driver for that matter:

    graph = EmptyGraph.instance()
    g = graph.traversal().withRemote('conf/remote-graph.properties')
    

    the results you receive are disconnected from the database. In TinkerPop we call that state "detached". So vertices returned from g.V() are in a "detached" state and you can't directly interact with them as though they are backed by the database for storing their properties.

    All database mutations should occur through the Traversal API (i.e. Gremlin). So, if you want to add a property to all vertices in your graph, you might do:

    g.V().property('name','Santosh').iterate()