title: Spark SQL - Find the greatest number of countries a passenger has been
body: <p>I have a data-frame as the following...</p>
  <pre><code>+-----------+--------+----+---+----------+
  |passengerId|flightId|from| to|      date|
  +-----------+--------+----+---+----------+
  |       3173|      41|  fr| cn|2017-01-11|
  |       3173|      48|  cn| at|2017-01-13|
  |       3173|      57|  at| pk|2017-01-17|
  |       3173|      71|  pk| il|2017-01-21|
  |       3173|     118|  il| se|2017-02-12|
  |       3173|     137|  se| iq|2017-02-18|
  |       3173|     154|  iq| at|2017-02-24|
  |       3173|     231|  at| ar|2017-03-22|
  |       3173|     245|  ar| cl|2017-03-28|
  |       3173|     270|  cl| sg|2017-04-08|
  |       3173|     287|  sg| iq|2017-04-14|
  |       3173|     308|  iq| nl|2017-04-21|
  |       3173|     317|  nl| dk|2017-04-24|
  |       3173|     336|  dk| se|2017-04-29|
  |       3173|     463|  se| th|2017-06-14|
  |       3173|     480|  th| th|2017-06-20|
  |       3173|     650|  th| th|2017-08-21|
  |       3173|     660|  th| nl|2017-08-26|
  |       3173|     670|  nl| sg|2017-09-01|
  |       3173|     695|  sg| ca|2017-09-10|
  +-----------+--------+----+---+----------+
  </code></pre>
  <p>I would like to find the greatest number of countries a passenger has been in and not include the starting country. For example, if the countries a passenger was in were: at -&gt; pk -&gt; il -&gt; se -&gt; iq -&gt; at, the correct answer would be 4 countries.
  The output should be in the following format:</p>
  <pre><code>Passenger ID    Longest Run
  3173                4
  1234                n
  …                   …
  </code></pre>