title: How to create a new RDD without nested transformation
body: <p>I would like to create a RDD with records in the following format:</p>
  
  <p>(trip, (starting station details), (ending station details))</p>
  
  <pre><code>import org.apache.spark._
  
  val input1 = sc.textFile("data/trips/*")
  val header1 = input1.first // to skip the header row
  val trips = input1.filter(_ != header1).map(_.split(","))
  
  val input2 = sc.textFile("data/stations/*")
  val header2 = input2.first // to skip the header row
  val stations = input2.filter(_!=header2).map(_.split(",")).keyBy(_(0).toInt)
  
  def pjoined (joined: (Array[String], Array[String], Array[String])) = {
      println(""+joined._1.deep.mkString(",")+"; "+joined._2.deep.mkString(",")+"; "+joined._3.deep.mkString(","))
  }
  
  val joinedtrips = trips.map(tup =&gt; (tup, (stations.filter(_._1==tup(4).toInt).first._2), (stations.filter(_._1==tup(7).toInt).first._2)))
  joinedtrips.take(5).foreach(pjoined)
  </code></pre>
  
  <p>The second last line fails with the following error:</p>
  
  <blockquote>
    <p>org.apache.spark.SparkException: RDD transformations and actions can only be invoked by the driver, not inside of other transformations; for example, rdd1.map(x => rdd2.values.count() * x) is invalid because the values transformation and count action cannot be performed inside of the rdd1.map transformation. </p>
  </blockquote>
  
  <p>What would be the proper and efficient way to achieve this?</p>
  
  <p>stations.csv:</p>
  
  <pre><code>station_id,name,lat,long,dockcount,landmark,installation,notes
  2,San Jose Diridon Caltrain Station,37.329732,-121.901782,27,San Jose,8/6/2013,
  3,San Jose Civic Center,37.330698,-121.888979,15,San Jose,8/5/2013,
  ...
  </code></pre>
  
  <p>trips.csv:</p>
  
  <pre><code>Trip ID,Duration,Start Date,Start Station,Start Terminal,End Date,End Station,End Terminal,Bike #,Subscription Type,Zip Code
  4258,114,8/29/2013 11:33,San Jose City Hall,10,8/29/2013 11:35,MLK Library,11,107,Subscriber,95060
  4265,151,8/29/2013 11:40,San Francisco City Hall,58,8/29/2013 11:42,San Francisco City Hall,58,520,Subscriber,94110
  ...
  </code></pre>
  
  <p><code>station_id</code> in stations.csv is to match with <code>Start Terminal</code> (index 4) and <code>End Terminal</code> (index 7) in trips.csv</p>