title: Turn RDD in Spark with key/[value] pairs into key/value pairs for each value in the values list
body: <p>I'm doing transformations on an RDD derived from an Avro Schema.  My Avro class looks something like this:</p>
  
  <pre><code>public class myAvroSchema {
      public String myKey;
      public Collection&lt;Value&gt; myValues;
      public Object someOtherObject;
  }
  </code></pre>
  
  <p>The current transformation I'm performing on the data set is as follows:</p>
  
  <pre><code>JavaRDD&lt;myAvroSchema&gt; myResult = AvroRDD.create(mySparkContext);
  myResult.filter(aResult -&gt; !aResult.getmyValues().isEmpty())
      .mapToPair(aResult -&gt; Tuple.of(aResult.getKey(), aResult.getMyValues());
  </code></pre>
  
  <p>This gives me a <code>JavaRDD&lt;String, Collection&lt;Value&gt;&gt;</code>, but what I really want is to return back <code>JavaRDD&lt;String, Value&gt;</code>.  </p>
  
  <p>I can't figure out how to take my <code>&lt;Key&gt;,Collection&lt;Value&gt;</code> pair and flatten out the values so that there are now multiple rows with the same key, but a different value for each row.  </p>
  
  <p>For example, say my result looks something like this:</p>
  
  <pre><code>&lt;KeyA, [Value1, Value2]&gt;
  &lt;KeyB, [Value3, Value4]&gt;
  </code></pre>
  
  <p>I would like to transform it to look like this:</p>
  
  <pre><code>&lt;KeyA, Value1&gt;
  &lt;KeyA, Value2&gt;
  &lt;KeyB, Value3&gt;
  &lt;KeyB, Value4&gt;
  </code></pre>