title: How to JOIN 3 RDD's using Spark Scala
body: <p>I want to join <code>3 tables</code> using <code>spark rdd</code>. I achieved my objective using spark sql but when I tried to join it using Rdd I am not getting the desired results. Below is my query using <code>spark SQL</code> and the <code>output</code>:</p>
  
  <pre><code>scala&gt; actorDF.as("df1").join(movieCastDF.as("df2"),$"df1.act_id"===$"df2.act_id").join(movieDF.as("df3"),$"df2.mov_id"===$"df3.mov_id").
  filter(col("df3.mov_title")==="Annie Hall").select($"df1.act_fname",$"df1.act_lname",$"df2.role").show(false)
  +---------+---------+-----------+                                               
  |act_fname|act_lname|role       |
  +---------+---------+-----------+
  |Woody    |Allen    |Alvy Singer|
  +---------+---------+-----------+
  </code></pre>
  
  <p>Now I created the <code>pairedRDDs</code> for three datasets and it is as below :</p>
  
  <pre><code>scala&gt; val actPairedRdd=actRdd.map(_.split("\t",-1)).map(p=&gt;(p(0),(p(1),p(2),p(3))))
  
  scala&gt; actPairedRdd.take(5).foreach(println)
  
  (101,(James,Stewart,M))
  (102,(Deborah,Kerr,F))
  (103,(Peter,OToole,M))
  (104,(Robert,De Niro,M))
  (105,(F. Murray,Abraham,M))
  
  scala&gt; val movieCastPairedRdd=movieCastRdd.map(_.split("\t",-1)).map(p=&gt;(p(0),(p(1),p(2))))
  movieCastPairedRdd: org.apache.spark.rdd.RDD[(String, (String, String))] = MapPartitionsRDD[318] at map at &lt;console&gt;:29
  
  scala&gt; movieCastPairedRdd.foreach(println)
  (101,(901,John Scottie Ferguson))
  (102,(902,Miss Giddens))
  (103,(903,T.E. Lawrence))
  (104,(904,Michael))
  (105,(905,Antonio Salieri))
  (106,(906,Rick Deckard))
  
  
  scala&gt; val moviePairedRdd=movieRdd.map(_.split("\t",-1)).map(p=&gt;(p(0),(p(1),p(2),p(3),p(4),p(5),p(6))))
  moviePairedRdd: org.apache.spark.rdd.RDD[(String, (String, String, String, String, String, String))] = MapPartitionsRDD[322] at map at &lt;console&gt;:29
  
  scala&gt; moviePairedRdd.take(2).foreach(println)
  (901,(Vertigo,1958,128,English,1958-08-24,UK))
  (902,(The Innocents,1961,100,English,1962-02-19,SW))  
  </code></pre>
  
  <p>Here <code>actPairedRdd</code> and <code>movieCastPairedRdd</code> is linked with each other and <code>movieCastPairedRdd</code> and <code>moviePairedRdd</code> is linked since they have common column.<br>
  Now when I join all the three datasets I am not getting any data  </p>
  
  <pre><code>scala&gt; actPairedRdd.join(movieCastPairedRdd).join(moviePairedRdd).take(2).foreach(println)  
  </code></pre>
  
  <p>I am getting blank records. So where am I going wrong ?? Thanks in advance </p>