title: Spark Datasets groupByKey doesn't work (Java)
body: <p>I try to use Dataset's groupByKey method. I can't figure out the problem and <strong>can't find</strong> any working example which <strong>uses groupByKey</strong>.</p>
  
  <p>So let me point out the points, I am looking for in the solution:</p>
  
  <ol>
  <li>I want to use groupByKey - there are a lot of example using groupBy("key").agg(function), I know it but don't want to use them (education purposes)</li>
  <li>I want to use Java - many examples use Scala, again don't want it.</li>
  <li>The function should preferably be written as lambda expression.</li>
  </ol>
  
  <p>Here is what I did:</p>
  
  <pre><code>//Inner class
  public static class Bean implements Serializable {
      private static final long serialVersionUID = 1L;
      private String k;
      private int something;
  
      public Bean(String name, int value) {
          k = name;
          something = value;
      }
  
      public String getK() {return k;}
      public int getSomething() {return something;}
  
      public void setK(String k) {this.k = k;}
      public void setSomething(int something) {this.something = something;}
  }
  
  //usage
  List&lt;Bean&gt; debugData = new ArrayList&lt;Bean&gt;();
  debugData.add(new Bean("Arnold", 18));
  debugData.add(new Bean("Bob", 7));
  debugData.add(new Bean("Bob", 13));
  debugData.add(new Bean("Bob", 15));
  debugData.add(new Bean("Alice", 27));
  Dataset&lt;Row&gt; df = sqlContext.createDataFrame(debugData, Bean.class);
  df.groupByKey(row -&gt; {new Bean(row.getString(0), row.getInt(1));}, Encoders.bean(Bean.class)); //doesn't compile
  </code></pre>
  
  <p>The error I am getting:</p>
  
  <ol>
  <li>Ambiguous method call - The IDE shows warning about both Function1 and MapFunction are matching.</li>
  <li>The getString and getInt cannot be resolved</li>
  <li>I can't show/print the result</li>
  </ol>