Extract byte from Spark BinaryType
<p>I have a table with a binary column of type BinaryType:</p>

<pre><code>&gt;&gt;&gt; df.show(3)
+--------+--------------------+
|       t|               bytes|
+--------+--------------------+
|0.145533|[10 50 04 89 00 3...|
|0.345572|[60 94 05 89 80 9...|
|0.545574|[99 50 68 89 00 7...|
+--------+--------------------+
only showing top 3 rows
&gt;&gt;&gt; df.schema
StructType(List(StructField(t,DoubleType,true),StructField(bytes,BinaryType,true)))
</code></pre>

<p>If I extract the first byte of the binary, I get an exception from Spark:</p>

<pre><code>&gt;&gt;&gt; df.select(n["t"], df["bytes"].getItem(0)).show(3)
AnalysisException: u"Can't extract value from bytes#477;"
</code></pre>

<p>A cast to <code>ArrayType(ByteType)</code> also didn't work:</p>

<pre><code>&gt;&gt;&gt; df.select(n["t"], df["bytes"].cast(ArrayType(ByteType())).getItem(0)).show(3)
AnalysisException: u"cannot resolve '`bytes`' due to data type mismatch: cannot cast BinaryType to ArrayType(ByteType,true) ..."
</code></pre>

<p>How can I extract the bytes?</p>