Gremlin Python mergeV on match doesnt update properties

64 views
Skip to first unread message

Hugo Ferney Alvarez Lucena

unread,
Jan 29, 2025, 9:28:38 PMJan 29
to Gremlin-users
I'm working with gremlin python and AWS Neptune, and I'm trying to update vertex properties with MergeV step and option OnMatch, but instead of update the value, it looks like append the value on a list, someone know how to update vertex properties with merge?
El presente correo contiene información y/o adjuntos confidenciales, de propiedad del grupo empresarial Bold y/o legalmente protegidos. Si recibió este correo por error, por favor notifíquelo de inmediato al emisor, elimínelo y no revele su contenido ni realice copias del mismo / This email contains confidential, proprietary to the Bold bussines group and/or legally protected information and/or attachments. If you have received this email in error, please notify the sender immediately, delete it and do not disclose its contents or make copies of it.

Cole Greer

unread,
Feb 3, 2025, 12:23:32 PMFeb 3
to Gremlin-users
Hi Hugo,
I believe your question has already been answered in the TinkerPop discord. Just to close the loop over here, what you are seeing is a result of Neptune using "set cardinality" for properties instead of "single". If you are using a database which supports TinkerPop 3.7.0 or newer, the correct syntax to specify single cardinality for a property is as follows:

from gremlin_python.process.traversal import Merge, T, CardinalityValue g.merge_v({T.id_: "x1234"}) .option(Merge.on_create, {T.label: 'Dog', 'name': 'Toby', 'age': 10}) .option(Merge.on_match, {'age': CardinalityValue.single(11)}) .toList()

If it is not possible to upgrade to a database which supports TinkerPop 3.7, then the following example should work. I generally wouldn't recommend using the following syntax unless necessary as it's effectively abusing the onMatch traversal to directly write the updated properties, instead of producing a property map as intended:

g.merge_v({T.id_: "x1234"}) .option(Merge.on_create, {T.label: 'Dog', 'name': 'Toby', 'age': 10}) .option(Merge.on_match, __.side_effect(__.property(Cardinality.single, "age", 11)).constant(dict())) .toList()

Cole Greer
Reply all
Reply to author
Forward
0 new messages