I am trying to count the appearances of specific Items at a specific date.
My input's structure is Date\tItem1:AppearencesOfItem1,...,ItemN:AppearencesOfItemN
Example
20/10/2000\tItem1:1,Item2:5
20/10/2000\tItem1:2
21/10/2000\tItem1:5
In order to do that, I create the following PairRdd structure:
[(20/10/2000, (Item1, 1))
(20/10/2000, (Item2, 5))
(20/10/2000, (Item1, 5))
(21/10/2000, (Item1, 5))]
and then groupByKey on the date which leads to:
[(20/10/2000, Iterable[(Item1, 1), (Item2, 5), (Item1, 5))
(21/10/2000, Iterable[(Item1, 5)]
What I want to do after this step is reduce the value of these pairs and sum the appearances of the items that share the same key so that the outcome will become like:
[(20/10/2000, Iterable[(Item1, 6), (Item2, 5))
(21/10/2000, Iterable[(Item1, 5)]
However I haven't figured a way to reduce on the value of these pairRdds. Is my approach wrong in the first place?