Apache Spark update a row in an RDD or Dataset based on another row
<p>I'm trying to figure how I can update some rows based on another another row.</p>

<p>For example, I have some data like</p>

<pre><code>Id | useraname | ratings | city
--------------------------------
1, philip, 2.0, montreal, ...
2, john, 4.0, montreal, ...
3, charles, 2.0, texas, ...
</code></pre>

<p>I want to update the users in the same city to the same groupId (either 1 or 2)</p>

<pre><code>Id | useraname | ratings | city
--------------------------------
1, philip, 2.0, montreal, ...
1, john, 4.0, montreal, ...
3, charles, 2.0, texas, ...
</code></pre>

<p>How can I achieve this in my RDD or Dataset ?</p>

<p>So just for sake of completeness, what if the <code>Id</code> is a String, the dense rank won't work ?</p>

<p>For example ?</p>

<pre><code>Id | useraname | ratings | city
--------------------------------
a, philip, 2.0, montreal, ...
b, john, 4.0, montreal, ...
c, charles, 2.0, texas, ...
</code></pre>

<p>So the result looks like this:</p>

<pre><code>grade | useraname | ratings | city
--------------------------------
a, philip, 2.0, montreal, ...
a, john, 4.0, montreal, ...
c, charles, 2.0, texas, ...
</code></pre>