Imagine a csv as follow :
a,b,c,d
1,1,0,0
0,1,1,0
...
I want to obtain automatically a DF with 4 columns a,b,c,d.
A manual technique can be :
val rdd = sc.textFile(path).map(_.split(","))
val cols = (0 until rdd.first.size).map(_.toString).toArray
val df = rdd.map{ case Array(a, b, c, d) => (a, b, c, d) }.toDF(cols:_*)
The problem with this technique is that i have to precise manually the number of columns a,b,c,d which can be problematic with hundreds or more features.
I imagine that it exist a more useful method probably passing by sparkSession but i don't want to have to precise any schema.