title: Spark - creating schema programmatically with different data types
body: <p>I have a dataset consisting of 7-8 fields which are of type String, Int &amp; Float.</p>
  
  <p>Am trying to create Schema by Programmatic approach by using this :</p>
  
  <pre><code>val schema = StructType(header.split(",").map(column =&gt; StructField(column, StringType, true)))
  </code></pre>
  
  <p>And Then mapping it to Row type like :</p>
  
  <pre><code>val dataRdd = datafile.filter(x =&gt; x!=header).map(x =&gt; x.split(",")).map(col =&gt; Row(col(0).trim, col(1).toInt, col(2).toFloat, col(3), col(4) ,col(5), col(6), col(7), col(8)))
  </code></pre>
  
  <p>But after creating DataFrame when i use DF.show() it gives error for the Integer field.</p>
  
  <p>So how to create such schema where we have multiple data type in the dataset</p>