title: Spark "CodeGenerator: failed to compile" with Dataset.groupByKey
body: <p>I'm new to both Scala and Spark, so hopefully someone can let me know where I'm going wrong here.</p>
  
  <p>I have a three-column dataset (id, name, year) and I want to find the most recent year for each name.  In other words:</p>
  
  <pre><code>BEFORE                                          AFTER
  | id_1 | name_1 | 2015 |                        | id_2 | name_1 | 2016 |
  | id_2 | name_1 | 2016 |                        | id_4 | name_2 | 2015 |
  | id_3 | name_1 | 2014 | 
  | id_4 | name_2 | 2015 |
  | id_5 | name_2 | 2014 |
  </code></pre>
  
  <p>I thought <code>groupByKey</code> and <code>reduceGroups</code> would get the job done:</p>
  
  <pre><code>val latestYears = ds
    .groupByKey(_.name)
    .reduceGroups((left, right) =&gt; if (left.year &gt; right.year) left else right)
    .map(group =&gt; group._2)
  </code></pre>
  
  <p>But it gives this error, and spits out a lot of generated Java code:</p>
  
  <pre><code>ERROR CodeGenerator: failed to compile: 
  org.codehaus.commons.compiler.CompileException: 
  File 'generated.java', Line 21, Column 101: Unknown variable or type "value4"
  </code></pre>
  
  <p>Interestingly, if I create a dataset with just the name and year columns, it works as expected. </p>
  
  <hr>
  
  <p>Here's the full code I'm running:</p>
  
  <pre><code>object App {
  
    case class Record(id: String, name: String, year: Int)
  
    def main(args: Array[String]) {
      val spark = SparkSession.builder().master("local").appName("test").getOrCreate()
      import spark.implicits._
  
      val ds = spark.createDataset[String](Seq(
          "id_1,name_1,2015",
          "id_2,name_1,2016",
          "id_3,name_1,2014",
          "id_4,name_2,2015",
          "id_5,name_2,2014"
        ))
        .map(line =&gt; {
          val fields = line.split(",")
          new Record(fields(0), fields(1), fields(2).toInt)
        })
  
      val latestYears = ds
        .groupByKey(_.name)
        .reduceGroups((left, right) =&gt; if (left.year &gt; right.year) left else right)
        .map(group =&gt; group._2)
  
      latestYears.show()
    }
  
  
  }
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT:</strong> I believe this may be a bug with Spark v2.0.1.  After downgrading to v2.0.0, this no longer occurs.</p>