title: Apache Spark SQL NumberFormatException
body: <p>I am using Spark 1.2 for some data processing. I have created a schema using StructField.</p>
  
  <pre><code>val exampleSchema = StructType(Array(StructField("SerialNo",StringType,true),StructField("Date",DateType,true),StructField("Value",IntegerType,true)))
  
  val exampleRowRDD = rawData.map(_.split(",")).map(p =&gt; Row(p(0),repairDate(p(1)), p(2).toInt) )
  
  
  val schemaRDD = sqlContext.applySchema(exampleRowRDD, exampleSchema)
  
  schemaRDD.registerTempTable("ExampleTable")
  </code></pre>
  
  <p>Now when I am running the query against the table, I get this error:</p>
  
  <pre><code>java.lang.NumberFormatException: For input string: ""
      at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
      at java.lang.Integer.parseInt(Integer.java:504)
      at java.lang.Integer.parseInt(Integer.java:527)
      at scala.collection.immutable.StringLike$class.toInt(StringLike.scala:229)
      at scala.collection.immutable.StringOps.toInt(StringOps.scala:31)
      at $line16.$read$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$anonfun$2.apply(&lt;console&gt;:49)
      at $line16.$read$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$anonfun$2.apply(&lt;console&gt;:49)
      at scala.collection.Iterator$$anon$11.next(Iterator.scala:328)
      at org.apache.spark.sql.columnar.InMemoryRelation$$anonfun$3$$anon$1.next(InMemoryColumnarTableScan.scala:122)
      at org.apache.spark.sql.columnar.InMemoryRelation$$anonfun$3$$anon$1.next(InMemoryColumnarTableScan.scala:112)
      at org.apache.spark.storage.MemoryStore.unrollSafely(MemoryStore.scala:249)
      at org.apache.spark.CacheManager.putInBlockManager(CacheManager.scala:163)
      at org.apache.spark.CacheManager.getOrCompute(CacheManager.scala:70)
      at org.apache.spark.rdd.RDD.iterator(RDD.scala:228)
      at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:35)
      at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:263)
      at org.apache.spark.rdd.RDD.iterator(RDD.scala:230)
      at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:35)
      at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:263)
      at org.apache.spark.rdd.RDD.iterator(RDD.scala:230)
      at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:35)
      at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:263)
      at org.apache.spark.rdd.RDD.iterator(RDD.scala:230)
  </code></pre>
  
  <p>I know my data has null values, and I tried to treat the null values with Option, Some, None method, but then Spark SQL doesn't recognize the data type. So the bottom line is for my "Value" column all the values should be an integer but null can't be converted into the integer. 
  What should I do? Working sample code example will be appreciated.</p>