I have a list of maps which correspond to records that I will receive in streaming, I need to take each record and upsert it.
I have seen many examples that work fine with just one vertex at a time, such that:
g.V('Amy').outE().where(inV().hasId('John')).
fold().
coalesce(
unfold(),
addE('manages').from(V('Amy')).to(V('John'))).
property('duration', '1year')
Works just fine, my issue lies in the replication of those steps for each map inside the list.
I am currently using gremlin on Amazon Neptune Notebooks, if that makes any difference.
At the moment I am able to insert a record if it does not exist or just retreive it if it exists. Basically a "get or insert" functionality. How can I update each property of each record if it already exists?
My current query for the get or insert:
g.inject([['memshpnum':'13464406186','cmpcod':'LM','upddat':'2019-03-01 00:00:00','ccp_loaded_date':'2022-11-22T15:29:59.933Z','cusnum':'7531272','T.id': '7531272#ifl', 'T.label': 'ccp_node_customer', 'status': 'pend'],
['memshpnum':'00170674487','cmpcod':'LM','upddat':'2019-03-01 00:00:00','ccp_loaded_date':'2022-11-22T15:29:59.933Z','cusnum':'3076059','T.id': '3076059#ifl', 'T.label': 'ccp_node_customer'],
['memshpnum':'20203784496','cmpcod':'LM','upddat':'2019-04-01 00:00:00','ccp_loaded_date':'2022-11-22T15:29:59.933Z','cusnum':'3075659','T.id': '727745#ifl', 'T.label': 'ccp_node_customer'],
['memshpnum':'20203784498','cmpcod':'LM','upddat':'2019-04-01 00:00:00','ccp_loaded_date':'2022-11-22T15:29:59.933Z','cusnum':'3076058','T.id': '727365#ifl', 'T.label': 'ccp_node_customer']
]).unfold().as("properties").
where(select("properties").unfold().filter(select(keys).is('T.label').or().is('T.cusnum')).select(values)).fold().
coalesce(unfold(),
addV(select('properties').unfold().filter(select(keys).is('T.label')).select(values)).as("vertex").
property(T.id, select('properties').unfold().filter(select(keys).is('T.id')).select(values)).
sideEffect(select("properties").
unfold().filter(select(keys).is(without('T.label','T.id'))).as("kv").
select("vertex").
property(select("kv").by(keys), select("kv").by(values))
)
)
And amongst the things I have tried is this query:
g.inject([
['memshpnum':'13464406186','cmpcod':'LM','upddat':'2019-03-01 00:00:00','ccp_loaded_date':'2022-11-22T15:29:59.933Z','cusnum':'7531272','T.id': '7531272#ifl', 'T.label': 'ccp_node_customer', 'status': 'pend'],
['memshpnum':'00170674487','cmpcod':'LM','upddat':'2019-03-01 00:00:00','ccp_loaded_date':'2022-11-22T15:29:59.933Z','cusnum':'3076059','T.id': '3076059#ifl', 'T.label': 'ccp_node_customer'],
['memshpnum':'20203784496','cmpcod':'LM','upddat':'2019-04-01 00:00:00','ccp_loaded_date':'2022-11-22T15:29:59.933Z','cusnum':'3075659','T.id': '727745#ifl', 'T.label': 'ccp_node_customer'],
['memshpnum':'20203784498','cmpcod':'LM','upddat':'2019-04-01 00:00:00','ccp_loaded_date':'2022-11-22T15:29:59.933Z','cusnum':'3076058','T.id': '727365#ifl', 'T.label': 'ccp_node_customer']
]).unfold().as("properties").
where(select("properties").unfold().filter(select(keys).is('T.label').or().is('T.cusnum')).select(values)).fold().
coalesce(unfold()
.property(select('properties').unfold().filter(select(keys).is(without('T.label','T.id'))).select(keys), select('properties').unfold().filter(select(keys).is(without('T.label','T.id'))).select(values)),
addV(select('properties').unfold().filter(select(keys).is('T.label')).select(values)).as("vertex").
property(T.id, select('properties').unfold().filter(select(keys).is('T.id')).select(values)).
sideEffect(select("properties").
unfold().filter(select(keys).is(without('T.label','T.id'))).as("kv").
select("vertex").
property(select("kv").by(keys), select("kv").by(values))
)
).toList()
However, I get an "Failed to interpret Gremlin query: The provided traverser does not map to a value" error.