Spark function to explain: aggregate
Let's take a look at the official document definition of the aggregate function:
Aggregate the elements of each partition, and then the results for all the partitions, using given combine functions and a neutral "zero value". This function can return a different result type, U, than the type of this RDD, We need one operation for merging a T into an U and one operation for merging two U's, as in scala.TraversableOnce. Both of these functions are allowed to modify and return their first argument instead of creating a new U to avoid memory allocation.The aggregate function aggregates the elements inside each partition, and then uses the combine function to combine the results of each partition with the initial value (zeroValue). The type of the final return of this function does not need to be consistent with the element type in RDD.