Inititaly I thought this was an easy problem, but I just can’t figure it out.
Here is a simplified example. I have 8 different people buying some items from a store. Afterwards I want to look at all the items and sort them into groups so that each overlapping initial shopping goes into the same new group.
input would look like this:
| person | items |
| ------ | ----------------- |
| 1| [B, A]|
| 2| [C, A]|
| 3| [E, I, D]|
| 4| [F, G]|
| 5| [F]|
| 6| [F, H]|
| 7| [J, A]|
| 8| [K, J]|
and output should look like this:
| bag | items |
| ----| -------------- |
| 1| [A, B, C, J, K]|
| 2| [E, I, D]|
| 3| [F, G, H]|
I tried crossJoin, array_intersect, concating arrays and also doing all this in several loops. But while it eventually leads to bag 1 ([A, B, C, J, K]), I cannot easily identify the smaller bags and at what point the group is complete. Am I overthinking this?