title: How to use orderby() with descending order in Spark window functions?
body: <p>I need a window function that partitions by some keys (=column names), orders by another column name and returns the rows with top x ranks. </p>
  
  <p>This works fine for ascending order:</p>
  
  <pre><code>def getTopX(df: DataFrame, top_x: String, top_key: String, top_value:String): DataFrame ={
      val top_keys: List[String] = top_key.split(", ").map(_.trim).toList
      val w = Window.partitionBy(top_keys(1),top_keys.drop(1):_*)
         .orderBy(top_value)
      val rankCondition = "rn &lt; "+top_x.toString
      val dfTop = df.withColumn("rn",row_number().over(w))
        .where(rankCondition).drop("rn")
    return dfTop
  }
  </code></pre>
  
  <p>But when I try to change it to <code>orderBy(desc(top_value))</code> or <code>orderBy(top_value.desc)</code> in line 4, I get a syntax error. What's the correct syntax here? </p>