I hava a RDD and a Array[String],I want to convert RDD to DataFrame,the Array[String]'s value are colnames,but DataFrame.toDf() function need a String* type
this is toDF()'s source code:
def toDF(colNames: String*): DataFrame = ds.toDF(colNames : _*)
this is my code:
val sqlContext = new SQLContext(sc)
import sqlContext.implicits._
val arr=Array(
(1,2),
(3,2),
(4,2),
(5,2),
(7,2)
)
val colNames=Array("first","second")
val df = sc.parallelize(arr,2).toDF("??","??")
this is my expect result:
+-----+------+
|first|second|
+-----+------+
| 1| 2|
| 3| 2|
| 4| 2|
| 5| 2|
| 7| 2|
+-----+------+