Let us see how to apply schema programmatically
val fields = s.split(" ").map( e=>{
val f = e.split(":")(0) // f is the field name
val t = if(e.split(":")(1) == "Int") IntegerType else StringType //t is type
StructField(f, t, nullable = false)})
val ordersRDD = spark.sparkContext.textFile("/Users/itversity/Reasearch/data/r etail_db/orders").
map(e=> { val a = e.split(",")
Row(a(0).toInt,a(1),a(2).Int,a(3))
val ordersDF = spark.createDataframe(ordersRDD,schema)