title: aggregate multiple columns in spark window function
body: <p>I am trying aggregation for multiple columns. Here is my scenario.</p>
  
  <p>I have a columns like this TagID,ListnerID,Timestamp and RSSI_weightage.</p>
  
  <p>I want to select the highest rssi_weightage's for each TagID. And Also I need to pick the hightest Timestamp for the above association.</p>
  
  <p>Example.</p>
  
  <pre><code>TagID,ListnerID,Timestamp,RSSI_Weightage
  2,101,1496745906,90
  3,102,1496745907,70
  3,104,1496745906,80
  2,101,1496745909,60
  4,106,1496745908,60
  
  My expected output
  
  2,101,1496745909,90
  3,104,1496745907,80
  4,106,1496745908,60
  </code></pre>
  
  <p>Explanation </p>
  
  <p>For TagID 2 the highest rssi_weighatge is 90.But the latest timestamp is 1496745909.That is my first row .Same thing I did for all tagID's.</p>
  
  <p>The above is my expected output. I tried like this.</p>
  
  <pre><code>val window = Window.partitionBy("tagShortID", "ListenerShortID").orderBy("RSSI_Weightage","Timestamp")
   val prox = averageDF.withColumn("rank", row_number().over(window)).where($"rank" === 1) 
  </code></pre>
  
  <p>But the above statement not works properly. I am getting incorrect results.Also If I apply desc in order by, It throws error.</p>