Apply match-case to a Spark Column?
<p>I have a Spark 2.0.0 Dataset with a column of <code>Foo</code> objects, like this for example <code>val ds: Dataset[(int, Foo, int)]</code>.  <code>Bar</code> is an extractor of <code>Foo</code>.  I'd like to be able to add a column constructed using a match-case statement (or any arbitrarily complex statement really).  Something like this: <code>ds.withColumn("extracted", $"_2" match { case Bar(x) =&gt; x })</code>.  What is the best way to achieve this behavior in Spark?</p>

<p><strong>Update:</strong><br>
@T.Gawęda and @zero323 - Thank you both for your thoughtful comments.  I think my answer lies in this sentence: "it is not possible to patten match over a <code>Column</code> to extract data."  I was indeed using a <code>Dataset[Row]</code> but I had overly simplified down to a <code>Dataset[(int, Foo, int)]</code>.  The reason I was leaning towards using <code>withColumn</code> rather than <code>map</code> was because (1) I was trying to avoid referencing any of the other columns (they didn't figure into the match-case function) and (2) I wanted to reference the Foo/Bar column by name (as the location of the column in the <code>Row</code> was unknown).</p>