Sorting and ranking in apache spark scala?
<p>I wanted to do ranking in spark, as follows:</p>

<p><strong>Input:</strong></p>

<pre><code>5.6
5.6
5.6
6.2
8.1
5.5
5.5
</code></pre>

<p><strong>Ranks:</strong></p>

<pre><code>1
1
1
2
3
0
0
0
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>Rank Input 
0     5.5
0     5.5
1     5.6
1     5.6
1     5.6
2     6.2
3     8.1
</code></pre>

<p>I wanted to know how I can sort these in spark and also get the same ranking as listed above. The requirements are:</p>

<ol>
<li>ranking starts with 0 not 1</li>
<li>this is a sample case for millions of records and one partition may be very large - I appreciate recommendation on how to rank using an internal sorting method</li>
</ol>

<p>I wanted to do this in scala. Can someone help me write code for this?</p>