Now that we have UDAFs this is a good use case to keep the aggregation all in SQL land (should be much faster)