[SPARK-2534] Avoid pulling in the entire RDD in groupByKey.

This should go into both master and branch-1.0.
There appear to be ~6 other functions of this type (defs that may be passed into closures), could these also be problematic?