You're trying to GROUP BY on a distributed data store; your code is the problem, not Spark SQL. Use CLUSTER BY - it's distributed sibling.
Query languages like HiveQL and Spark SQL were designed to look like SQL, but they're not.
Query languages like HiveQL and Spark SQL were designed to look like SQL, but they're not.