title: Spark GroupBy to map and keep all fields
body: <p>I want to groupby in order to map a Map.</p>
  <pre><code>case class Foo(
                            domain: String,
                            site: Long,
                            reason: String,
                            list: Long,
                            policy: Long,
                            action: Long,
                           )
  
  val f = Seq(
  Foo(&quot;domain&quot;, 1, &quot;reason1&quot;, 33, 44, 55),
    Foo(&quot;domain&quot;, 1, &quot;reason2&quot;, 33, 44, 55),
    Foo(&quot;domain&quot;, 2, &quot;reason3&quot;, 33, 66, 55),
    Foo(&quot;domain&quot;, 2, &quot;reason4&quot;, 33, 66, 55),
    Foo(&quot;domain&quot;, 1, &quot;reason5&quot;, 33, 88, 55),
  )
  
  
  val ds = f.toDS()
  </code></pre>
  <p>I know I can get the fields explicitly by:</p>
  <pre><code>import org.apache.spark.sql.functions.{map, collect_list}
  
  ds.groupBy($&quot;site&quot;).agg(collect_list(map($&quot;site&quot;, $&quot;reason&quot;))).collect()
  </code></pre>
  <p>But I want all fields (besides the aggregated one - <code>site</code>, basically <code>site</code> maps to all other fields in the current row) - my original case class is much larger than this, and might change. Any other way to do so without getting all col.</p>
  <p>Any cleaner way to do so?</p>
  <p>Using Spark 3, Scala 2.12</p>