title: Flatten an RDD - Nested lists in value of key value pair
body: <p>It took me awhile to figure this out and I wanted to share my solution. Improvements are definitely welcome.</p>
  
  <p>References: <a href="https://stackoverflow.com/questions/29835518/flattening-a-scala-map-in-an-rdd">Flattening a Scala Map in an RDD</a>, <a href="https://stackoverflow.com/questions/24556813/spark-flatten-seq-by-reversing-groupby-i-e-repeat-header-for-each-sequence-in">Spark Flatten Seq by reversing groupby, (i.e. repeat header for each sequence in it)</a></p>
  
  <p>I have an RDD of the form: RDD[(Int, List[(String, List[(String, Int, Float)])])]</p>
  
  <p>Key: Int</p>
  
  <p>Value: List[(String, List[(String, Int, Float)])]</p>
  
  <p>With a goal of flattening to: RDD[(Int, String, String, Int, Float)]</p>
  
  <pre><code>binHostCountByDate.foreach(println)
  </code></pre>
  
  <p>Gives the example:</p>
  
  <pre><code>(516361, List((2013-07-15, List((s2.rf.ru,1,0.5), (s1.rf.ru,1,0.5))), (2013-08-15, List((p.secure.com,1,1.0)))))
  </code></pre>
  
  <p>The final RDD should give the following </p>
  
  <pre><code>(516361,2013-07-15,s2.rf.ru,1,0.5)
  (516361,2013-07-15,s1.rf.ru,1,0.5)
  (516361,2013-08-15,p.secure.com,1,1.0)
  </code></pre>