How do I split a Spark rdd Array[(String, Array[String])]?
<p>I'm practicing on doing sorts in the Spark shell. I have an rdd with about 10 columns/variables. I want to sort the whole rdd on the values of column 7. </p>

<pre><code>rdd
org.apache.spark.rdd.RDD[Array[String]] = ...
</code></pre>

<p>From what I gather the way to do that is by using sortByKey, which in turn only works on pairs. So I mapped it so I'd have a pair consisting of column7 (string values) and the full original rdd (array of strings)</p>

<pre><code>rdd2 = rdd.map(c =&gt; (c(7),c))
rdd2: org.apache.spark.rdd.RDD[(String, Array[String])] = ...
</code></pre>

<p>I then apply sortByKey, still no problem...</p>

<pre><code>rdd3 = rdd2.sortByKey()
rdd3: org.apache.spark.rdd.RDD[(String, Array[String])] = ...
</code></pre>

<p>But now <strong>how do I split off, collect and save that sorted original rdd</strong> from rdd3 (Array[String])? Whenever I try a split on rdd3 it gives me an error:</p>

<pre><code>val rdd4 = rdd3.map(_.split(',')(2))
&lt;console&gt;:33: error: value split is not a member of (String, Array[String])
</code></pre>

<p>What am I doing wrong here? Are there other, better ways to sort an rdd on one of its columns?</p>