[SPARK-2873] [SQL] using ExternalAppendOnlyMap to resolve OOM when aggregating

Using ExternalAppendOnlyMap to resolve OOM when aggregating.
Using "spark.shuffle.spill" to open it or not 
Hive udaf does not support yet for udaf need Serializable

Join has  the same problem. but using ExternalAppendOnlyMap as CoGroupedRDD  seems to reduce performance. i try another way by using ExternalAppendOnlyMap. but it needs testing .i will commit it in another batch.

Instead of doing the if check here, what do you think about this:
 - Create a trait called `Aggregate` that contains shared code.
 - Create two operators `OnHeapAggregation` and `ExternalAggregation`.
 - Choose which one to use in the planner based on the above configuration.