title: Combing rows in a spark dataframe
body: <p>If I have an input as below:</p>
  
  <pre>
  sno name    time
  1   hello   1
  1   hello   2
  1   hai 3
  1   hai 4
  1   hai 5
  1   how 6
  1   how 7
  1   are 8
  1   are 9
  1   how 10
  1   how 11
  1   are 12
  1   are 13
  1   are 14
  </pre>
  
  <p>I want to combine the fields having similar values in name as the below output format:</p>
  
  <pre>
  sno name timestart timeend
  1 hello 1 2
  1 hai 3 5
  1 how 6 7
  1 are 8 9
  1 how 10 11
  1 are 12 14
  </pre>
  
  <p>The input will be sorted according to time and only the records which are having the same name for repeated time intervals must be merged.
  I am trying to do using spark but I cannot figure out a way to do this using spark functions since I am new to spark. Any suggestions on the approach will be appreciated. </p>
  
  <p>I tried thinking of writing a user-defined function and applying maps to the data frame but I could not come up with the right logic for the function. </p>
  
  <p>PS: I am trying to do this using scala spark.</p>