title: How to create a graph from a CSV file using Graph.fromEdgeTuples in Spark Scala
body: <p>I'm new to <code>Spark</code> and <code>Scala</code>, and I'm trying to carry out a simple task of creating a graph from data in a text file. </p>
  
  <p><strong>From the documentation</strong> </p>
  
  <blockquote>
    <p><a href="https://spark.apache.org/docs/0.9.0/api/graphx/index.html#org.apache.spark.graphx.Graph" rel="nofollow">https://spark.apache.org/docs/0.9.0/api/graphx/index.html#org.apache.spark.graphx.Graph</a>$@fromEdges[VD,ED]%28RDD[Edge[ED]],VD%29%28ClassTag[VD],ClassTag[ED]%29:Graph[VD,ED] </p>
  </blockquote>
  
  <p>I can see that I can create a graph from <code>tuples of vertices</code>.</p>
  
  <p><strong>My simple text file looks like this, where each number is a vertex:</strong></p>
  
  <pre><code>v1 v3
  v2 v1
  v3 v4
  v4
  v5 v3
  </code></pre>
  
  <p>When I read the data from the file  </p>
  
  <blockquote>
    <p>val myVertices = myData.map(line=>line.split(" "))
    I get an RDD[Array[String]]. </p>
  </blockquote>
  
  <p><strong>My questions are:</strong></p>
  
  <ol>
  <li><p>If this is the right way to approach the problem, how do I turn the <code>RDD[Array[String]]</code> into the correct format, which according to the documentation is <code>RDD[(VertexId, VertexId)]</code> (also <code>VertexID</code> has to be of type long, and I am working with strings) </p></li>
  <li><p>Is there an alternative, easier way in which I can construct a graph from a similar structure of csv file?</p></li>
  </ol>
  
  <p>Any suggestion would be very welcome. Thanks!</p>