title: how to pivot Spark dataframe table?
body: <p>I have this table of 3 columns:</p>
  
  <pre><code>+---+----+----+
  | id|type| val|
  +---+----+----+
  |  1|   A|   0|
  |  2|   A|   0|
  |  4|   A|   0|
  |  2|   B|   1|
  |  4|   B|   1|
  +---+----+----+
  </code></pre>
  
  <p>and I would like to transforme it to something like:</p>
  
  <pre><code>+---+----+----+
  |   |   A|   B|
  +---+----+----+
  |  1|   0|   -|
  |  2|   1|   1|
  |  4|   0|   1|
  +---+----+----+
  </code></pre>
  
  <p>I tried this but didn't work:</p>
  
  <pre><code>val data_array = data.pivot(cols=['type'],rows=['id'],values='val')
  </code></pre>