title: Processing Apache Spark GraphX multiple subgraphs
body: <p>I have a parent Graph that I want to filter into multiple subgraphs, so I can apply a function to each subgraph and extract some data. My code looks like this:</p>
  
  <pre><code>val myTerms = &lt;RDD of terms I want to use to filter the graph&gt;
  val myVertices = ...
  val myEdges = ...
  val myGraph = Graph(myVertices, myEdges)
  
  val myResults : RDD[(&lt;Tuple&gt;)] = myTerms.map { x =&gt; mySubgraphFunction(myGraph, x) }
  </code></pre>
  
  <p>Where mySubgraphFunction is a function that creates a subgraph, performs a calculation, and returns a tuple of result data.</p>
  
  <p>When I run this, I get a Java null pointer exception at the point that mySubgraphFunction calls GraphX.subgraph. If I call collect on the RDD of terms, I can get this to work (also added persist on the RDDs for performance):</p>
  
  <pre><code>val myTerms = &lt;RDD of terms I want to use to filter the graph&gt;
  val myVertices = &lt;read RDD&gt;.persist(StorageLevel.MEMORY_ONLY_SER)
  val myEdges = &lt;read RDD&gt;.persist(StorageLevel.MEMORY_ONLY_SER)
  val myGraph = Graph(myVertices, myEdges)
  
  val myResults : Array[(&lt;Tuple&gt;)] = myTerms.collect().map { x =&gt;
                   mySubgraphFunction(myGraph, x) }
  </code></pre>
  
  <p>Is there a way to get this to work where I don't have to call collect() (i.e. make this a distributed operation)? I'm creating ~1k subgraphs and the performance is slow.</p>