I have this Vector[String]:
user_uid,score,value
255938,34096,8
259117,34599,10
253664,28891,7
how can I convert it to DataFrame?
I already tried this:
val dataInVectorRow = dataInVectorString
.map(_.split("\\s+"))
.map(x => Row.fromSeq(x))
val fileRdd: RDD[Row] = sparkSession.sparkContext
.parallelize(dataInVectorRow)
val schema = StructType(Seq(
StructField("col1", StringType),
StructField("col2", StringType),
StructField("col3", StringType)
))
val df_from_file = sparkSession.sqlContext.createDataFrame(fileRdd, schema)
df_from_file
But it give me this error:
Caused by: java.lang.RuntimeException: Error while encoding: java.lang.ArrayIndexOutOfBoundsException: 1