title: spark dataframe groupby multiple times
body: <pre><code>val df = (Seq((1, "a", "10"),(1,"b", "12"),(1,"c", "13"),(2, "a", "14"),
                (2,"c", "11"),(1,"b","12" ),(2, "c", "12"),(3,"r", "11")).
            toDF("col1", "col2", "col3"))
  </code></pre>
  
  <p>So I have a spark dataframe with 3 columns.</p>
  
  <pre><code>+----+----+----+
  |col1|col2|col3|
  +----+----+----+
  |   1|   a|  10|
  |   1|   b|  12|
  |   1|   c|  13|
  |   2|   a|  14|
  |   2|   c|  11|
  |   1|   b|  12|
  |   2|   c|  12|
  |   3|   r|  11|
  +----+----+----+
  </code></pre>
  
  <p>My requirement is actually I need to perform two levels of groupby as explained below.</p>
  
  <p>Level1: 
  If I do groupby on col1 and do a sum of Col3. I will get below two columns.
  1. col1
  2. sum(col3)
  I will loose col2 here.</p>
  
  <p>Level2: 
  If i want to again group by on col1 and col2 and do a sum of Col3 I will get below 3 columns.
  1. col1
  2. col2
  3. sum(col3)</p>
  
  <p>My requirement is actually I need to perform two levels of groupBy and have these two columns(sum(col3) of level1, sum(col3) of level2) in a final one dataframe.</p>
  
  <p>How can I do this, can anyone explain?</p>
  
  <p>spark : 1.6.2
  Scala : 2.10</p>