title: how to select by max(date) with spark dataframe API
body: <p>Given the following dataset</p>
  
  <pre><code>id v  date
  1  a1 1
  1  a2 2
  2  b1 3
  2  b2 4
  </code></pre>
  
  <p>I want to select only the last value (regarding the date) for each id.</p>
  
  <p>I've came up with this code :</p>
  
  <pre><code>scala&gt; val df = sc.parallelize(List((41,"a1",1), (1, "a2", 2), (2, "b1", 3), (2, "b2", 4))).toDF("id", "v", "date")
  df: org.apache.spark.sql.DataFrame = [id: int, v: string, date: int]
  
  scala&gt; val agg = df.groupBy("id").max("date")
  agg: org.apache.spark.sql.DataFrame = [id: int, max(date): int]
  
  scala&gt; val res = df.join(agg, df("id") === agg("id") &amp;&amp; df("date") === agg("max(date)"))
  16/11/14 22:25:01 WARN sql.Column: Constructing trivially true equals predicate, 'id#3 = id#3'. Perhaps you need to use aliases.
  res: org.apache.spark.sql.DataFrame = [id: int, v: string, date: int, id: int, max(date): int]
  </code></pre>
  
  <p>Is there a better way (more idiomatic, …) ?</p>
  
  <p>Bonus : how to perform a max on a date column and avoid this error  <code>Aggregation function can only be applied on a numeric column.</code> ?</p>