title: Transform tuple to matrix in Spark
body: <p>I have an rdd list of tuples and values that looks like this. There are thousands of different pairings.</p>
  <pre><code>(A, B), 1
  (B, C), 2
  (C, D), 1
  (A, D), 1
  (D, A), 5
  </code></pre>
  <p>I want to transform the tuple value pairs into a matrix that corresponds to the pairs. I didn't see any easy way to do this in spark.</p>
  <pre><code>+---+------+------+------+------+
  |   |  A   |  B   |  C   |  D   |
  +---+------+------+------+------+
  | A | -    | 1    | NULL | 1    |
  | B | NULL | -    | 2    | NULL |
  | C | NULL |      | -    | 1    |
  | D | 5    | NULL | NULL | -    |
  +---+------+------+------+------+
  </code></pre>