title: Spark: Mapgroups on a Dataset
body: <p>I'm trying this mapgroups function on the below dataset
  and not sure why I'm getting 0 for the "Total Value" column.
  Am I missing something here??? Please advice</p>
  
  <p>Spark Version - 2.0
  Scala Version - 2.11</p>
  
  <pre><code>case class Record(Hour: Int, Category: String,TotalComm: Double, TotalValue: Int)
  val ss = (SparkSession)
  import ss.implicits._
  
  val df: DataFrame = ss.sparkContext.parallelize(Seq(
  (0, "cat26", 30.9, 200), (0, "cat26", 22.1, 100), (0, "cat95", 19.6, 300), (1, "cat4", 1.3, 100),
  (1, "cat23", 28.5, 100), (1, "cat4", 26.8, 400), (1, "cat13", 12.6, 250), (1, "cat23", 5.3, 300),
  (0, "cat26", 39.6, 30), (2, "cat40", 29.7, 500), (1, "cat4", 27.9, 600), (2, "cat68", 9.8, 100),
  (1, "cat23", 35.6, 500))).toDF("Hour", "Category","TotalComm", "TotalValue")
  
  val resultSum = df.as[Record].map(row =&gt; ((row.Hour,row.Category),(row.TotalComm,row.TotalValue)))
  .groupByKey(_._1).mapGroups{case(k,iter) =&gt; (k._1,k._2,iter.map(x =&gt; x._2._1).sum,iter.map(y =&gt; y._2._2).sum)}
  .toDF("KeyHour","KeyCategory","TotalComm","TotalValue").orderBy(asc("KeyHour"))
  
  resultSum.show()
  
  +-------+-----------+---------+----------+
  |KeyHour|KeyCategory|TotalComm|TotalValue|
  +-------+-----------+---------+----------+
  |      0|      cat26|     92.6|         0|
  |      0|      cat95|     19.6|         0|
  |      1|      cat13|     12.6|         0|
  |      1|      cat23|     69.4|         0|
  |      1|       cat4|     56.0|         0|
  |      2|      cat40|     29.7|         0|
  |      2|      cat68|      9.8|         0|
  +-------+-----------+---------+----------+  
  </code></pre>