I have a table like below:
| id | item |
| -- | ------------------------------------ |
| 1 | {order_id: 1, item_id: 1, price: 10} |
| 2 | {order_id: 1, item_id: 2, price: 11} |
| 3 | {order_id: 2, item_id: 3, price: 12} |
| 4 | {order_id: 2, item_id: 4, price: 13} |
I need to aggregate the rows in the table into the following:
| order_id | order |
| -------- | ------------------------------------------------------------------------ |
| 1 | {order_id: 1, items: [{item_id: 1, price: 10}, {item_id: 2, price: 11}]} |
| 2 | {order_id: 2, items: [{item_id: 3, price: 12}, {item_id: 4, price: 13}]} |
Initially I thought UDAF could do the trick, but when I implement an aggregator UDAF function, I'm not sure what to return in merge method as if order id is different, they can't be merged.