title: Pivot non-numeric table in Spark Scala
body: <p>Is it possible to pivot a table with non-numeric values in Spark Scala? I have reviewed the following two Stack questions.</p>
  
  <p><a href="https://stackoverflow.com/questions/30244910/pivot-spark-dataframe">How to pivot DataFrame?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/32015033/list-in-the-case-when-statement-in-spark-sql">List in the Case-When Statement in Spark SQL</a></p>
  
  <p>Following the steps in the "List in the Case-When" question, I can transform my data so that each data type is a column, but there is a row for each entity-data type combination.</p>
  
  <pre><code>id    tag    value
  1     US     foo
  1     UK     bar
  1     CA     baz
  2     US     hoo
  2     UK     hah
  2     CA     wah
  
  id    US    UK    CA
  1     foo
  1           bar
  1                 baz
  2     hoo
  2           hah
  3                 wah
  </code></pre>
  
  <p>Is there a "first non-null" function that can collapse the multiple rows for each entity into just one?</p>
  
  <pre><code>id    US    UK    CA
  1     foo   bar   baz
  2     hoo   hah   wah
  </code></pre>