title: Spark: RuntimeException: java.lang.String is not a valid external type for schema of date
body: <p>This works fine:</p>
  <pre><code>import org.apache.spark.sql.types.{StructType, StructField, StringType, IntegerType, DateType}
  import org.apache.spark.sql.functions._
  
  val df = Seq( (&quot;2018-01-01&quot;, &quot;2018-01-31&quot;, 80)
              , (&quot;2018-01-07&quot;,&quot;2018-01-10&quot;, 10)
              , (&quot;2018-01-07&quot;,&quot;2018-01-31&quot;, 10)
              , (&quot;2018-01-11&quot;,&quot;2018-01-31&quot;, 5)
              , (&quot;2018-01-25&quot;,&quot;2018-01-27&quot;, 5)
              , (&quot;2018-02-02&quot;,&quot;2018-02-23&quot;, 100)
              ).toDF(&quot;sd&quot;,&quot;ed&quot;,&quot;coins&quot;)
  
  val schema = List((&quot;sd&quot;, &quot;date&quot;), (&quot;ed&quot;, &quot;date&quot;), (&quot;coins&quot;, &quot;integer&quot;))
  val newColumns = schema.map(c =&gt; col(c._1).cast(c._2))
  val newDF = df.select(newColumns:_*)
  newDF.show(false)
  </code></pre>
  <p>and is a work-around for this below issue I present:</p>
  <pre><code>import org.apache.spark.sql.types.{StructType, StructField, StringType, IntegerType, DateType};
  
  val someData = Seq(
                       Row(&quot;2018-01-01&quot;,&quot;2018-01-31&quot;, 80)
                     , Row(&quot;2018-01-07&quot;,&quot;2018-01-10&quot;, 10)
                     , Row(&quot;2018-01-07&quot;,&quot;2018-01-31&quot;, 10)
                     , Row(&quot;2018-01-11&quot;,&quot;2018-01-31&quot;, 5)
                     , Row(&quot;2018-01-25&quot;,&quot;2018-01-27&quot;, 5)
                     , Row(&quot;2018-02-02&quot;,&quot;2018-02-23&quot;, 100)
                    )
  
  val someSchema = List(
    StructField(&quot;sd&quot;, DateType, true),
    StructField(&quot;ed&quot;, DateType, true),
    StructField(&quot;coins&quot;, IntegerType, true),
  )
  
  val dfA = spark.createDataFrame(
    spark.sparkContext.parallelize(someData),
    StructType(someSchema)
  )
  
  dfA.show(false)
  </code></pre>
  <p>generates an error as follows:</p>
  <pre><code>Caused by: RuntimeException: java.lang.String is not a valid external type for schema of date
  </code></pre>
  <p>I am aware of the int, bigint problem and indicate a workaround for date in the first snippet, but I cannot seem to use the Date Type - I would like to know how on the 2nd snippet, continuing in this vein.</p>