Gremlin with AWS Neptune
Hey Friends,
I am working on a project using AWS Neptune with gremlin query language on gremlingo driver.
I realize the latest version of neptune is 1.3.1, and tinkerpop version is 3.6.4.
I want to write a query to batch upsert property and then build edge.
The relationship looks like the following:
(User) -> [:HAS_USER_ACCOUNT] -> (GremlinUser)
I am trying to use mergeV to upsert vertice and mergeE to upsert edge
g.
MergeV(map[interface{}]interface{}{
gremlingo.T.Id: universalId,
}).
Option(gremlingo.Merge.OnCreate, gremlinUserOnCreate).
Option(gremlingo.Merge.OnMatch, gremlinUserOnMatch).
Id().
MergeV(map[interface{}]interface{}{
gremlingo.T.Id: userUUID,
gremlingo.T.Label: "User",
"email": user["email"],
}).
Option(gremlingo.Merge.OnCreate, parentUserOnCreate).
Option(gremlingo.Merge.OnMatch, parentUserOnMatch).
Id().
MergeE(map[interface{}]interface{}{
gremlingo.T.Label: "HAS_USER_ACCOUNT",
gremlingo.Direction.Out: gremlingo.Merge.OutV,
gremlingo.Direction.In: gremlingo.Merge.InV,
}).
Option(gremlingo.Merge.OutV, map[interface{}]interface{}{
gremlingo.T.Label: "User",
"email": user["email"],
}).
Option(gremlingo.Merge.InV, map[interface{}]interface{}{
gremlingo.T.Label: "GremlinUser",
"email": user["email"],
}).
Id().Next()
Conditions I have:
1. if the email can not be found, i am expecting to silent ignoe it, there is scenario that email can not be found for mergeE scenario
2. mergeV/mergeE does not handle single cardinality properly, it always add property to a set, I can not find a neat way to by pass it in tinkerpop 3.6.4Solution:Jump to solution
note that Neptune 1.3.2.1 now supports the functionality of TinkerPop 3.7.x. You can read more about it at https://aws.amazon.com/blogs/database/exploring-new-features-of-apache-tinkerpop-3-7-x-in-amazon-neptune/
Amazon Web Services
Exploring new features of Apache TinkerPop 3.7.x in Amazon Neptune ...
Amazon Neptune 1.3.2.0 now supports the Apache TinkerPop 3.7.x release line, introducing many major new features and improvements. In this post, we highlight the features that have the greatest impact on Gremlin developers using Neptune, to help you understand the implications of upgrading to these versions of Neptune and TinkerPop.
4 Replies
The upgrade doc that discusses the ability to do this in 3.7.x also shows what the work around was previously: https://tinkerpop.apache.org/docs/current/upgrade/#_map_and_cardinality
You would have to make use of
sideEffect
within the option()
to define cardinality for the property.so there is no way for me to do it in neptune, which only supports 3.6.4...
Amazon Neptune Engine version 1.3.1.0 (2024-03-06) - Amazon Neptune
Amazon Neptune engine update, version 1.3.1.0 on 2024-03-06.
Solution
note that Neptune 1.3.2.1 now supports the functionality of TinkerPop 3.7.x. You can read more about it at https://aws.amazon.com/blogs/database/exploring-new-features-of-apache-tinkerpop-3-7-x-in-amazon-neptune/
Amazon Web Services
Exploring new features of Apache TinkerPop 3.7.x in Amazon Neptune ...
Amazon Neptune 1.3.2.0 now supports the Apache TinkerPop 3.7.x release line, introducing many major new features and improvements. In this post, we highlight the features that have the greatest impact on Gremlin developers using Neptune, to help you understand the implications of upgrading to these versions of Neptune and TinkerPop.