title: NullPointerException in Scala Spark, appears to be caused be collection type?
body: <p><code>sessionIdList</code> is of type : </p>
  
  <pre><code>scala&gt; sessionIdList
  res19: org.apache.spark.rdd.RDD[String] = MappedRDD[17] at distinct at &lt;console&gt;:30
  </code></pre>
  
  <p>When I try to run below code : </p>
  
  <pre><code>val x = sc.parallelize(List(1,2,3)) 
  val cartesianComp = x.cartesian(x).map(x =&gt; (x))
  
  val kDistanceNeighbourhood = sessionIdList.map(s =&gt; {
      cartesianComp.filter(v =&gt; v != null)
  })
  
  kDistanceNeighbourhood.take(1)
  </code></pre>
  
  <p>I receive exception : </p>
  
  <pre><code>14/05/21 16:20:46 ERROR Executor: Exception in task ID 80
  java.lang.NullPointerException
          at org.apache.spark.rdd.RDD.filter(RDD.scala:261)
          at $line94.$read$$iwC$$iwC$$iwC$$iwC$$anonfun$1.apply(&lt;console&gt;:38)
          at $line94.$read$$iwC$$iwC$$iwC$$iwC$$anonfun$1.apply(&lt;console&gt;:36)
          at scala.collection.Iterator$$anon$11.next(Iterator.scala:328)
          at scala.collection.Iterator$$anon$10.next(Iterator.scala:312)
          at scala.collection.Iterator$class.foreach(Iterator.scala:727)
  </code></pre>
  
  <p>However if I use : </p>
  
  <pre><code>val l = sc.parallelize(List("1","2")) 
  val kDistanceNeighbourhood = l.map(s =&gt; {    
      cartesianComp.filter(v =&gt; v != null)
  })
  
  kDistanceNeighbourhood.take(1)
  </code></pre>
  
  <p>Then no exception is displayed</p>
  
  <p>The difference between the two code snippets is that in first snippet sessionIdList is of type : </p>
  
  <pre><code>res19: org.apache.spark.rdd.RDD[String] = MappedRDD[17] at distinct at &lt;console&gt;:30
  </code></pre>
  
  <p>and in second snippet "l" is of type</p>
  
  <pre><code>scala&gt; l
  res13: org.apache.spark.rdd.RDD[String] = ParallelCollectionRDD[32] at parallelize at &lt;console&gt;:12
  </code></pre>
  
  <p>Why is this error occuring ?</p>
  
  <p>Do I need to convert sessionIdList to ParallelCollectionRDD in order to fix this ?</p>