title: Apache Spark: how to create a counter
body: <p>I'm doing my first steps with scala. I work with Cloudera VM.</p>
  
  <p>I have a csv separate with ;. I want to split each line and to create a val loans with a sequential counter. I wrote a map to do these tasks.</p>
  
  <p>My code is below</p>
  
  <pre><code>scala&gt; val loans: RDD[(VertexId, ComplaintNodeDate)] =
   |  sc.textFile("/home/cloudera/complaints_loan.csv").filter(!_.startsWith("DateReceived")).
   | map {line =&gt; 
   | val row = line split ';'
   | var initialValue1 = initialValue2 + 1L
   |  initialValue2 = initialValue1
   | (initialValue2, ComplaintLoan(row(0),row(1), row(2), row(3), row(4)))
   | }
  </code></pre>
  
  <p>I get the following error</p>
  
  <pre><code> java.io.IOException: Failed to create local dir in /tmp/spark-3940587c-c7b4-460c-be02-02660ed17f05/blockmgr-d5286d12-401a-4d68-b8b9-7654d319800d/21.
  at org.apache.spark.storage.DiskBlockManager.getFile(DiskBlockManager.scala:73)
  at org.apache.spark.storage.DiskStore.contains(DiskStore.scala:167)
  at org.apache.spark.storage.BlockManager.org$apache$spark$storage$BlockManager$$getCurrentBlockStatus(BlockManager.scala:404)
  at org.apache.spark.storage.BlockManager.doPut(BlockManager.scala:805)
  at org.apache.spark.storage.BlockManager.putIterator(BlockManager.scala:637)
  at org.apache.spark.storage.BlockManager.putSingle(BlockManager.scala:991)
  at org.apache.spark.broadcast.TorrentBroadcast.writeBlocks(TorrentBroadcast.scala:98)
  at org.apache.spark.broadcast.TorrentBroadcast.&lt;init&gt;(TorrentBroadcast.scala:84)
  at org.apache.spark.broadcast.TorrentBroadcastFactory.newBroadcast(TorrentBroadcastFactory.scala:34)
  at org.apache.spark.broadcast.TorrentBroadcastFactory.newBroadcast(TorrentBroadcastFactory.scala:29)
  at org.apache.spark.broadcast.BroadcastManager.newBroadcast(BroadcastManager.scala:62)
  at org.apache.spark.SparkContext.broadcast(SparkContext.scala:1051)
  at org.apache.spark.SparkContext.hadoopFile(SparkContext.scala:761)
  at org.apache.spark.SparkContext.textFile(SparkContext.scala:589)
  at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:43)
  at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:54)
  at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:56)
  at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:58)
  at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:60)
  at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:62)
  at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:64)
  at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:66)
  at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:68)
  at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:70)
  at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:72)
  at $iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:74)
  at $iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:76)
  at $iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:78)
  at $iwC$$iwC.&lt;init&gt;(&lt;console&gt;:80)
  at $iwC.&lt;init&gt;(&lt;console&gt;:82)
  at &lt;init&gt;(&lt;console&gt;:84)
  at .&lt;init&gt;(&lt;console&gt;:88)
  at .&lt;clinit&gt;(&lt;console&gt;)
  at .&lt;init&gt;(&lt;console&gt;:7)
  at .&lt;clinit&gt;(&lt;console&gt;)
  at $print(&lt;console&gt;)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at org.apache.spark.repl.SparkIMain$ReadEvalPrint.call(SparkIMain.scala:1065)
  at org.apache.spark.repl.SparkIMain$Request.loadAndRun(SparkIMain.scala:1338)
  at org.apache.spark.repl.SparkIMain.loadAndRunReq$1(SparkIMain.scala:840)
  at org.apache.spark.repl.SparkIMain.interpret(SparkIMain.scala:871)
  at org.apache.spark.repl.SparkIMain.interpret(SparkIMain.scala:819)
  at org.apache.spark.repl.SparkILoop.reallyInterpret$1(SparkILoop.scala:856)
  at org.apache.spark.repl.SparkILoop.interpretStartingWith(SparkILoop.scala:901)
  at org.apache.spark.repl.SparkILoop.reallyInterpret$1(SparkILoop.scala:874)
  at org.apache.spark.repl.SparkILoop.interpretStartingWith(SparkILoop.scala:901)
  at org.apache.spark.repl.SparkILoop.reallyInterpret$1(SparkILoop.scala:874)
  at org.apache.spark.repl.SparkILoop.interpretStartingWith(SparkILoop.scala:901)
  at org.apache.spark.repl.SparkILoop.reallyInterpret$1(SparkILoop.scala:874)
  at org.apache.spark.repl.SparkILoop.interpretStartingWith(SparkILoop.scala:901)
  at org.apache.spark.repl.SparkILoop.reallyInterpret$1(SparkILoop.scala:874)
  at org.apache.spark.repl.SparkILoop.interpretStartingWith(SparkILoop.scala:901)
  at org.apache.spark.repl.SparkILoop.reallyInterpret$1(SparkILoop.scala:874)
  at org.apache.spark.repl.SparkILoop.interpretStartingWith(SparkILoop.scala:901)
  at org.apache.spark.repl.SparkILoop.reallyInterpret$1(SparkILoop.scala:874)
  at org.apache.spark.repl.SparkILoop.interpretStartingWith(SparkILoop.scala:901)
  at org.apache.spark.repl.SparkILoop.reallyInterpret$1(SparkILoop.scala:874)
  at org.apache.spark.repl.SparkILoop.interpretStartingWith(SparkILoop.scala:901)
  at org.apache.spark.repl.SparkILoop.command(SparkILoop.scala:813)
  at org.apache.spark.repl.SparkILoop.processLine$1(SparkILoop.scala:656)
  at org.apache.spark.repl.SparkILoop.innerLoop$1(SparkILoop.scala:664)
  at org.apache.spark.repl.SparkILoop.org$apache$spark$repl$SparkILoop$$loop(SparkILoop.scala:669)
  at org.apache.spark.repl.SparkILoop$$anonfun$org$apache$spark$repl$SparkILoop$$process$1.apply$mcZ$sp(SparkILoop.scala:996)
  at org.apache.spark.repl.SparkILoop$$anonfun$org$apache$spark$repl$SparkILoop$$process$1.apply(SparkILoop.scala:944)
  at org.apache.spark.repl.SparkILoop$$anonfun$org$apache$spark$repl$SparkILoop$$process$1.apply(SparkILoop.scala:944)
  at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135)
  at org.apache.spark.repl.SparkILoop.org$apache$spark$repl$SparkILoop$$process(SparkILoop.scala:944)
  at org.apache.spark.repl.SparkILoop.process(SparkILoop.scala:1058)
  at org.apache.spark.repl.Main$.main(Main.scala:31)
  at org.apache.spark.repl.Main.main(Main.scala)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:569)
  at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:166)
  at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:189)
  at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:110)
  at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
  
  
   scala&gt; 
  </code></pre>
  
  <p>Is it right my code?</p>