I've tried slicing and dicing this query multiple ways in order to allow the DB to a majority of the bulk processing vs. on the client side. To do this I plan on injecting a map, we can start with the two in the example below. Unfortunately merging or adding coalesce logic using hasLabel() and other results in the actual iteration of the list not happening. Example below:
The query below is what I'm trying to get to work. Unfortunately it seems to return the same ID. This tells me it's not iterating once fired off.
g.inject(
[
[stock_height:111, sh_id:"sh123", inputs: [house: "inputhouse123ia"], outputs: [[house: "outputhouse123oa", group_id: "gid-123a"],[house: "outputhouse123ob", group_id: "gid-123b"]]],
[stock_height:111, sh_id:"sh1234", inputs: [house: "inputhouse1234ia"], outputs: [[house: "outputhouse1234oa", group_id: "gid-1234a"],[house: "outputhouse1234ob", group_id: "gid-1234b"]]]
]).
unfold().as('sh').
select('outputs').
unfold().as('output').select('group_id').as('gid').
mergeV([(label): 'Peoplegroup']).property('group_id', select('gid')).id()
Output: [ 17846400, 17846400, 17846400, 17846400 ]
Using select outside of addV() or mergeV() seems to work fine.
g.inject(
[
[stock_height:111, sh_id:"sh123", inputs: [house: "inputhouse123ia"], outputs: [[house: "outputhouse123oa", group_id: "gid-123a"],[house: "outputhouse123ob", group_id: "gid-123b"]]],
[stock_height:111, sh_id:"sh1234", inputs: [house: "inputhouse1234ia"], outputs: [[house: "outputhouse1234oa", group_id: "gid-1234a"],[house: "outputhouse1234ob", group_id: "gid-1234b"]]]
]).
unfold().as('sh').
select('outputs').
unfold().as('output').select('group_id').as('gid').
select('gid')
Output: [ "gid-123a", "gid-123b", "gid-1234a", "gid-1234b" ]
Any ideas? I'm at a loss of new ideas, and any help would be greatly appreciated.
I was hoping to add 4 new gid vertices to the graph, or return the id's which already exist. The map up could be simplified for testing purposes.
Because your
mergeVis only matching on a label, the first time it is executed, none exist. So it creates aPeoplegroupnode. After that each of the othermergeVfind that initial one. You will notice that by the end the property is actually set togid-1234b(the last one) as it has matched each one and replaced the property. To get a different behavior you need to introduce something more unique to match on, or just inject the whole map and not usepropertyat all.You can actually observe this behavior by changing the cardinality on the
propertystep tolist: