I am doing a groupby over a week column in a PYSPARK dataframe and collecting new different IDs between two sucessive weeks number.
I tried doing a groupby over week column then aggregating the collect_set method on the dataframe to get all the available IDs, then i compared the lists one by one to get the different ID between two successive lists by week number as below:
Input :
| Week | ID |
|---|---|
| 1 | ID_1 |
| 1 | ID_2 |
| 1 | ID_3 |
| 2 | ID_1 |
| 2 | ID_4 |
| 2 | ID_5 |
| 3 | ID_6 |
OUTPUT:
| Week | ID_List | diff_list | new_different_ID_count |
|---|---|---|---|
| 1 | ID_1, ID_2,ID_3 | ID_1, ID_2, ID_3 | - |
| 2 | ID_1, ID_4, ID_5 | ID_4, ID_5 | 2 |
| 3 | ID_2, ID_6 | ID_6 | 1 |
The probleme here is that as the huge number of IDs i have in my case (more than 9 million ID) the spark session is being killed due to an Out of Memory Error i think (Error 500)!
Is there any other solution to get the list of new different IDs beetween two successive weeks with PYSPARK ?