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

A new PR clone from PR 1822

Fix numbers of problems

Reuse the CompactBuffer from Spark Core to save memory and pointer dereferences as PR 1993

Hive UDAF not support external aggregate, for hive AggregationBuffer need  serializable and hive GenericUDAFEvaluator has no method implement to merge two evaluators