I am trying to get modify vertices on a remote Gremlin Server using a traversal but it seems that only in the traversal in which a vertex is created I can also add properties, when starting a new traversal I properties are not added.
Scala/Java cluster connection setup code:
val mapper = GryoMapper.build()
val cluster = Cluster.build().serializer(new GryoMessageSerializerV1d0(mapper)).create
val client = cluster.connect[org.apache.tinkerpop.gremlin.driver.Client.ClusteredClient]()
val graph = EmptyGraph.instance()
val g = graph.traversal().withRemote(DriverRemoteConnection.using(cluster, "g"))
this works:
val v1 = g.addV("person").property("name","stephen").next()
this does not:
g.V(v1.id()).property("age","27")
this does not either and even throws a java.lang.IllegalStateException (propertyAdditionNotSupported) because the vertex is a org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertex:
v1.property("age","27")
If I use a Gremlin Console and remote connect to the Gremlin Server I do both without any issues.
:remote connect tinkerpop.server conf/remote.yaml
gremlin> :> g.addV('person').property('name','stephen')
==>v[82128]
gremlin> :> g.V(82128).property('age','27')
==>v[82128]
gremlin> :> g.V(82128).valueMap()
==>[name:[stephen],age:[27]]
Is the Java remote implementation bugged or am I missing something?
I'm not sure what Graph implementation you are using but this works for me with TinkerGraph:
gremlin> graph = EmptyGraph.instance()
==>emptygraph[empty]
gremlin> cluster = Cluster.open()
==>localhost/127.0.0.1:8182
gremlin> g = graph.traversal().withRemote(DriverRemoteConnection.using(cluster, "g"))
==>graphtraversalsource[emptygraph[empty], standard]
gremlin> v = g.addV().property('name','stephen').next()
==>v[0]
gremlin> g.V(v.id()).property('favorite','red')
==>v[0]
gremlin> g.V().valueMap()
==>[name:[stephen],favorite:[red]]
I will note than in your case you don't next() out the vertex from:
val v1 = g.addV("person").property("name","stephen")
I assume that even in Gremlin Scala syntax you should have to do:
val v1 = g.addV("person").property("name","stephen").next()
otherwise v1 will just be a Traversal instance and you get the id() of the Traversal and not the Vertex. So I think that should fix your problem.
Note that v1.property("age","27") will not work for the reason you explained - that vertex is "detached" and you can't work with it directly except by passing it back into another traversal. You should also be able to do this on most graphs:
gremlin> g.V(v).property('favorite','red')
==>v[0]
without referencing the id().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With