I’m assuming that the document field values are the same when a person ID occurs in both (identical records).
A couple of Java services using a HashMap should do the trick.
First, create a couple of helper Java services.
hashMap:put
–Inputs: map (object), key (object), value (object)
–Outputs: map (object)
IDataCursor idc = pipeline.getCursor();
java.util.HashMap map = (java.util.HashMap)IDataUtil.get(idc, “map”);
if(map == null)
map = new java.util.HashMap();
map.put(IDataUtil.get(idc, “key”), IDataUtil.get(idc, “value”);
IDataUtil.put(idc, “map”, map);
idc.destroy();
hashMap:valuesAsDocuments
–Inputs: map (object)
–Outputs: list (document list)
IDataCursor idc = pipeline.getCursor();
java.util.HashMap map = (java.util.HashMap)IDataUtil.get(idc, “map”);
IDataUtil.put(idc, “list”, map.values().toArray(new IData[0]));
idc.destroy();
Your merge steps can be:
LOOP over ‘/list1’
…hashMap:put – map list1/personID to key; list1 to value; map to map
LOOP over ‘/list2’
…hashMap:put – map list2/personID to key; list2 to value; map to map
hashMap.valuesAsDocuments – map to map
HashMap.put allows only unique keys. When a list2 entry with the same key as a list1 entry is put to the list, the list2 value (document) replaces the value that was there.
The valuesAsDocuments assumes that the type stored in the values portion of the map object is an IData object.
With this approach, these 2 lists:
list1 (personID, name, city)
1, Abe, Anaconda
2, Bill, Butte
3, Charlie, Cutbank
4, Dan, Dillon
list2
3, Charlie, Cutbank
5, Eamon, Ennis
6, Fred, Fort Benton
Will result in this document list:
1, Abe, Anaconda
2, Bill, Butte
3, Charlie, Cutbank
4, Dan, Dillon
5, Eamon, Ennis
6, Fred, Fort Benton
The put service could accept another input, initialCapacity, to allocate enough space up front but that might not be necessary.
I hope that’s what you were looking for!