01-29-2024 05:04 PM
I'm having trouble using the reduce function in a mapper which will subtotal two values across a two field compound key. For example, take the following input:
"myarray": [{
"key1": 1,
"key2": "A",
"value1": 5,
"value2": 10
}, {
"key1": 1,
"key2": "A",
"value1": 10,
"value2": 20
}, {
"key1": 2,
"key2": "A",
"value1": 15,
"value2": 30
}, {
"key1": 2,
"key2": "B",
"value1": 20,
"value2": 40
}
]
My desired result is as follows:
"myarray": [{
"key1": 1,
"key2": "A",
"value1": 15,
"value2": 30
}, {
"key1": 2,
"key2": "A",
"value1": 3,
"value2": 30
}, {
"key1": 2,
"key2": "B",
"value1": 4,
"value2": 40
}
]
Unfortunately due to use of an ultra pipeline, I cannot use a Group By snap and must resolve within a mapper. Appreciate any guidance from the community on how to best solve this.
Thanks!
01-30-2024 01:21 AM
Hello @ahouston,
Attached below is a sample pipeline where I did the calculation for the subtotal, I'm not sure if that's what you expect but you can take a look at it.
Mainly, first I'm grouping the same objects with same key1 and key2 and then I'm adding the value1 and value2.
Please let me know if this helps you.
Regards,
Aleksandar.