Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: rboccuzziHere is an example that might help. Actually, it is three examples.
The first one uses the (hidden) knowledge of how the Reduce-To-List node, and that it creates a variable called itemList. Here, I add a predicate that tests to see if the current DSO has already been added to the itemList, and only adds it if needed. The qty calculation just counts the length of the string when split by the delimiter, subtracting 2, as there is always going to be 2 more than expected, since the delimiter is the first and last in a list...even an empty list will have a delimiter here, so a split will give you a list of length 2, which correctly returns 0. So here I needed to add something to the predicate and the output exprs.
In the second example, I don't use the underlying knowledge of the itemList existence, and just do a sort unique to throw all the dups away...you mentioned this can't work, but I am not sure why, so I left this in to show how it could work; I might be missing something in the use case. In this, I throw away randomly any duplicate records, and then use the standard behavior of reduce to list. I added a count() expression and emited that to give you the count of the unique length...you could also add a filter after this reduce to list node and use the logic I used above in example 1 to just split("*").len() - 2 to get Qty.
In the third example, I highlight how doing a sort and then agg is a little better in de-duping, as you can control what gets dropped. You would want to add a sort criteria to the sort node, and then you will drop the last in the group on that agg node, and do the same as the reduce to list as the second example.
I hope this helps.
Cheers
Rich
Attachments:
Example Reduce To List.brg