title: Change Data Types for Dataframe by Schema in Scala Spark
body: <p>I have a dataframe without schema and every column stored as StringType such as:</p>
  
  <pre><code>ID | LOG_IN_DATE | USER
  1  | 2017-11-01  | Johns
  </code></pre>
  
  <p>Now I created a schema dataframe as <code>[(ID,"double"),("LOG_IN_DATE","date"),(USER,"string")]</code> and I would like to apply to the above Dataframe in Spark 2.0.2 with Scala 2.11.</p>
  
  <p>I already tried:</p>
  
  <pre><code>schema.map(x =&gt; df.withColumn(x._1, col(x._1).cast(x._2)))
  </code></pre>
  
  <p>There's no error while running this but afterwards when I call the df.schema, nothing is changed.</p>
  
  <p>Any idea on how I could programmatically apply the schema to df? My friend told me I can use <code>foldLeft</code> method but I don't think this is a method in Spark 2.0.2 neither in df nor rdd.</p>