There's more...

Given the direction for Spark which favors the Dataset/DataFrame paradigm over low level RDD coding, one must seriously consider the reasoning for doing groupBy() on an RDD. While there are legitimate situations for which the operation is needed, the readers are advised to reformulate their solution to take advantage of the SparkSQL subsystem and its optimizer called Catalyst.

The Catalyst optimizer takes into account Scala's powerful features such as pattern matching and quasiquotes while building an optimized query plan.

Get Apache Spark 2.x Machine Learning Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.