title: Unpivot in spark-sql/pyspark
body: <p>I have a problem statement at hand wherein I want to unpivot table in spark-sql/pyspark. I have gone through the documentation and I could see there is support only for pivot but no support for un-pivot so far.
  Is there a way I can achieve this?</p>
  
  <p>Let my initial table look like this:</p>
  
  <p><a href="https://i.stack.imgur.com/pXOBm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/pXOBm.png" alt="Let my initial table look like this"></a></p>
  
  <p>when I pivot this in pyspark using below mentioned command:</p>
  
  <pre><code>df.groupBy("A").pivot("B").sum("C")
  </code></pre>
  
  <p>I get this as the output:</p>
  
  <p><a href="https://i.stack.imgur.com/FQcED.png" rel="noreferrer"><img src="https://i.stack.imgur.com/FQcED.png" alt="After pivot table looks like this"></a></p>
  
  <p>Now I want to unpivot the pivoted table. In general this operation may/may not yield the original table based on how I've pivoted the original table.</p>
  
  <p>Spark-sql as of now doesn't provide out of the box support for unpivot. Is there a way I can achieve this?</p>