title: How can I convert a single Spark Row to a Scala object?
body: <p>I can read in a Spark dataframe as a custom object like this:</p>
  
  <pre><code>spark.read.csv("path/to/file").as[Gizmo]
  </code></pre>
  
  <p>But how can I convert a single Spark <code>Row</code> object to its equivalent case class? (If you're worried about <em>why</em> I want to do this, please consult <a href="https://stackoverflow.com/questions/50141827/how-do-i-perform-arbitrary-calculations-on-groups-of-records-in-a-spark-datafram">this question</a>.) Clearly Spark knows how to do this, but I don't see any straightforward way of accomplishing it (short of converting the <code>Row</code> into an RDD of length 1 and then converting back).</p>
  
  <pre><code>row.as[Gizmo] // doesn't work. What goes here?
  </code></pre>