title: Conditionally remove duplicates duplicated rows in spark dataset
body: <p>I would like to achieve the following thing:</p>
  
  <pre><code>val df1 = Seq(("a","x",20),("z","x",10),("b","y",7),("z","y",5),("c","w",1),("z","w",2)).toDS
  
  
  +---+---+---+
  | _1| _2| _3|
  +---+---+---+
  |  a|  x| 20|
  |  z|  x| 10|
  |  b|  y|  7|
  |  z|  y|  5|
  |  c|  w|  1|
  |  z|  w|  2|
  +---+---+---+
  </code></pre>
  
  <p>should be reduced to</p>
  
  <pre><code>val df2 = Seq(("a","x",30),("b","y",12),("c","w",3)).toDS
  
  +---+---+---+
  | _1| _2| _3|
  +---+---+---+
  |  a|  x| 30|
  |  b|  y| 12|
  |  c|  w|  3|
  +---+---+---+
  </code></pre>
  
  <p>I am aware of the <code>dropDuplicates()</code>command with its options. But for what I ould like to achieve this does not work. Somehow one has to detect the duplicates according to column <code>_2</code> and then one has to remove the always the row with the <code>z</code> entry in <code>_1</code> and add its <code>_3</code> value to the the <code>_3</code>column that one keeps.</p>
  
  <p>Thank you in advance.</p>