title: Spark groupByKey alternative
body: <p>According to Databricks best practices, Spark <code>groupByKey</code> should be avoided as Spark <code>groupByKey</code> processing works in a way that the information will be first shuffled across workers and then the processing will occur. <a href="http://databricks.gitbooks.io/databricks-spark-knowledge-base/content/best_practices/prefer_reducebykey_over_groupbykey.html" rel="nofollow noreferrer">Explanation</a></p>
  
  <p>So, my question is, what are the alternatives for <code>groupByKey</code> in a way that it will return the following in a distributed and fast way?</p>
  
  <pre><code>// want this
  {"key1": "1", "key1": "2", "key1": "3", "key2": "55", "key2": "66"}
  // to become this
  {"key1": ["1","2","3"], "key2": ["55","66"]}
  </code></pre>
  
  <p>Seems to me that maybe <code>aggregateByKey</code> or <code>glom</code> could do it first in the partition (<code>map</code>) and then join all the lists together (<code>reduce</code>).</p>