title: dataframe: how to groupBy/count then filter on count in Scala
body: <p>Spark 1.4.1 </p>
  
  <p>I encounter a situation where grouping by a dataframe, then counting and filtering on the 'count' column raises the exception below</p>
  
  <pre><code>import sqlContext.implicits._
  import org.apache.spark.sql._
  
  case class Paf(x:Int)
  val myData = Seq(Paf(2), Paf(1), Paf(2))
  val df = sc.parallelize(myData, 2).toDF()
  </code></pre>
  
  <p>Then grouping and filtering:</p>
  
  <pre><code>df.groupBy("x").count()
    .filter("count &gt;= 2")
    .show()
  </code></pre>
  
  <p>Throws an exception:</p>
  
  <pre><code>java.lang.RuntimeException: [1.7] failure: ``('' expected but `&gt;=' found count &gt;= 2
  </code></pre>
  
  <p><strong>Solution:</strong></p>
  
  <p>Renaming the column makes the problem vanish (as I suspect there is no conflict with the interpolated 'count' function'</p>
  
  <pre><code>df.groupBy("x").count()
    .withColumnRenamed("count", "n")
    .filter("n &gt;= 2")
    .show()
  </code></pre>
  
  <p>So, is that a behavior to expect, a bug or is there a canonical way to go around?</p>
  
  <p>thanks, alex</p>