title: Scala - Groupby and Max on pair RDD
body: <p>I am new in spark scala and want to find the max salary in each department</p>
  
  <pre><code>Dept,Salary
  Dept1,1000
  Dept2,2000
  Dept1,2500
  Dept2,1500
  Dept1,1700
  Dept2,2800
  </code></pre>
  
  <p>I implemented below code </p>
  
  <pre><code>import org.apache.spark.SparkContext
  import org.apache.spark.SparkContext._
  import org.apache.spark.SparkConf
  
  
  object MaxSalary {
    val sc = new SparkContext(new SparkConf().setAppName("Max Salary").setMaster("local[2]"))
  
    case class Dept(dept_name : String, Salary : Int)
  
    val data = sc.textFile("file:///home/user/Documents/dept.txt").map(_.split(","))
    val recs = data.map(r =&gt; (r(0), Dept(r(0), r(1).toInt)))
    val a = recs.max()???????
  })
  }
  </code></pre>
  
  <p>but stuck how to implement group by and max function. I am using pair RDD.</p>
  
  <p>Thanks</p>